summaryrefslogtreecommitdiff
path: root/apt-pkg/deb
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2017-06-26 17:47:38 +0200
committerDavid Kalnischkies <david@kalnischkies.de>2017-06-26 23:31:15 +0200
commitf68167a0e55c7261c9e61f0f39945cd0e908dabb (patch)
treeb7a2c179357e56be0248b80c8362dedcff87c40d /apt-pkg/deb
parent42654d08c2ca1bee18b6947a39228a35c2409deb (diff)
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
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r--apt-pkg/deb/debindexfile.cc33
1 files changed, 8 insertions, 25 deletions
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 <stdio.h>
#include <iostream>
+#include <memory>
#include <string>
#include <sstream>
@@ -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<pkgCacheListParser> 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<pkgCacheListParser> 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<pkgCacheListParser> 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
{