From 3d8232bf97ce11818fb07813a71136484ea1a44a Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 18 Jun 2015 17:33:15 +0200 Subject: fix memory leaks reported by -fsanitize Various small leaks here and there. Nothing particularily big, but still good to fix. Found by the sanitizers while running our testcases. Reported-By: gcc -fsanitize Git-Dch: Ignore --- apt-pkg/tagfile.cc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'apt-pkg/tagfile.cc') diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index 4c5505bf3..6d7d8185b 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -34,8 +34,10 @@ class pkgTagFilePrivate public: void Reset(FileFd * const pFd, unsigned long long const pSize) { - Fd = pFd; + if (Buffer != NULL) + free(Buffer); Buffer = NULL; + Fd = pFd; Start = NULL; End = NULL; Done = false; @@ -43,7 +45,7 @@ public: Size = pSize; } - pkgTagFilePrivate(FileFd * const pFd, unsigned long long const Size) + pkgTagFilePrivate(FileFd * const pFd, unsigned long long const Size) : Buffer(NULL) { Reset(pFd, Size); } @@ -54,6 +56,12 @@ public: bool Done; unsigned long long iOffset; unsigned long long Size; + + ~pkgTagFilePrivate() + { + if (Buffer != NULL) + free(Buffer); + } }; class pkgTagSectionPrivate @@ -127,7 +135,6 @@ void pkgTagFile::Init(FileFd * const pFd,unsigned long long Size) /* */ pkgTagFile::~pkgTagFile() { - free(d->Buffer); delete d; } /*}}}*/ -- cgit v1.2.3