From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.1 From: Aleksei Nikiforov To: devel@lists.altlinux.org Date: Tue, 10 Dec 2019 18:23:33 +0300 Message-Id: <20191210152343.33867-29-darktemplar@altlinux.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191210152343.33867-1-darktemplar@altlinux.org> References: <20191210152343.33867-1-darktemplar@altlinux.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Cc: Aleksei Nikiforov Subject: [devel] [PATCH for apt 28/38] Fix resource leaks in pkgCacheFile class X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Dec 2019 15:25:25 -0000 Archived-At: List-Archive: List-Post: --- apt/apt-pkg/cachefile.cc | 12 ++++++++++++ apt/apt-pkg/pkgcachegen.cc | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/apt/apt-pkg/cachefile.cc b/apt/apt-pkg/cachefile.cc index 1a5fa64..0ac882b 100644 --- a/apt/apt-pkg/cachefile.cc +++ b/apt/apt-pkg/cachefile.cc @@ -81,6 +81,12 @@ bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock) return false; // Read the caches + if (Map != nullptr) + { + delete Map; + Map = nullptr; + } + bool Res = pkgMakeStatusCache(*SrcList,Progress,&Map,!WithLock); Progress.Done(); if (Res == false) @@ -90,6 +96,12 @@ bool pkgCacheFile::BuildCaches(OpProgress &Progress,bool WithLock) if (_error->empty() == false) _error->Warning(_("You may want to run apt-get update to correct these problems")); + if (Cache != nullptr) + { + delete Cache; + Cache = nullptr; + } + Cache = new pkgCache(Map); if (_error->PendingError() == true) return false; diff --git a/apt/apt-pkg/pkgcachegen.cc b/apt/apt-pkg/pkgcachegen.cc index 654c81c..42f2d42 100644 --- a/apt/apt-pkg/pkgcachegen.cc +++ b/apt/apt-pkg/pkgcachegen.cc @@ -834,7 +834,14 @@ static bool CheckValidity(const string &CacheFile, FileIterator Start, } if (OutMap != 0) + { + if (*OutMap != nullptr) + { + delete *OutMap; + } + *OutMap = Map.UnGuard(); + } return true; } /*}}}*/ @@ -1130,6 +1137,11 @@ bool pkgMakeStatusCache(pkgSourceList &List,OpProgress &Progress, return false; if (OutMap != 0) { + if (*OutMap != nullptr) + { + delete *OutMap; + } + if (CacheF != 0) { delete Map.UnGuard(); -- 2.24.0