From f68167a0e55c7261c9e61f0f39945cd0e908dabb Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 26 Jun 2017 17:47:38 +0200 Subject: fix some unlikely memory leaks in error cases The error cases are just as unlikely as the memory leaks to ever cause real problems, but lets play it safe for correctness. Reported-By: scan-build & clang Gbp-Dch: Ignore --- apt-pkg/deb/debindexfile.cc | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) (limited to 'apt-pkg/deb') diff --git a/apt-pkg/deb/debindexfile.cc b/apt-pkg/deb/debindexfile.cc index c55847305..799144ecb 100644 --- a/apt-pkg/deb/debindexfile.cc +++ b/apt-pkg/deb/debindexfile.cc @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -66,7 +67,7 @@ bool debSourcesIndex::OpenListFile(FileFd &, std::string const &) } pkgCacheListParser * debSourcesIndex::CreateListParser(FileFd &) { - return NULL; + return nullptr; } uint8_t debSourcesIndex::GetIndexFlags() const { @@ -128,16 +129,10 @@ pkgCacheListParser * debTranslationsIndex::CreateListParser(FileFd &Pkg) if (Pkg.IsOpen() == false) return nullptr; _error->PushToStack(); - pkgCacheListParser * const Parser = new debTranslationsParser(&Pkg); + std::unique_ptr Parser(new debTranslationsParser(&Pkg)); bool const newError = _error->PendingError(); _error->MergeWithStack(); - if (newError) - { - delete Parser; - return nullptr; - } - else - return Parser; + return newError ? nullptr : Parser.release(); } /*}}}*/ // dpkg/status Index /*{{{*/ @@ -162,16 +157,10 @@ pkgCacheListParser * debStatusIndex::CreateListParser(FileFd &Pkg) if (Pkg.IsOpen() == false) return nullptr; _error->PushToStack(); - pkgCacheListParser * const Parser = new debStatusListParser(&Pkg); + std::unique_ptr Parser(new debStatusListParser(&Pkg)); bool const newError = _error->PendingError(); _error->MergeWithStack(); - if (newError) - { - delete Parser; - return nullptr; - } - else - return Parser; + return newError ? nullptr : Parser.release(); } /*}}}*/ // DebPkgFile Index - a single .deb file as an index /*{{{*/ @@ -244,16 +233,10 @@ pkgCacheListParser * debDebPkgFileIndex::CreateListParser(FileFd &Pkg) if (Pkg.IsOpen() == false) return nullptr; _error->PushToStack(); - pkgCacheListParser * const Parser = new debDebFileParser(&Pkg, DebFile); + std::unique_ptr Parser(new debDebFileParser(&Pkg, DebFile)); bool const newError = _error->PendingError(); _error->MergeWithStack(); - if (newError) - { - delete Parser; - return nullptr; - } - else - return Parser; + return newError ? nullptr : Parser.release(); } uint8_t debDebPkgFileIndex::GetIndexFlags() const { -- cgit v1.2.3-70-g09d2