summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/fileutl.cc
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/contrib/fileutl.cc
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/contrib/fileutl.cc')
-rw-r--r--apt-pkg/contrib/fileutl.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 8ce8d5baf..e87102cbc 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -2847,7 +2847,7 @@ std::string GetTempDir(std::string const &User)
FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * const TmpFd) /*{{{*/
{
char fn[512];
- FileFd * const Fd = TmpFd == NULL ? new FileFd() : TmpFd;
+ FileFd * const Fd = TmpFd == nullptr ? new FileFd() : TmpFd;
std::string const tempdir = GetTempDir();
snprintf(fn, sizeof(fn), "%s/%s.XXXXXX",
@@ -2858,12 +2858,16 @@ FileFd* GetTempFile(std::string const &Prefix, bool ImmediateUnlink, FileFd * co
if (fd < 0)
{
_error->Errno("GetTempFile",_("Unable to mkstemp %s"), fn);
- return NULL;
+ if (TmpFd == nullptr)
+ delete Fd;
+ return nullptr;
}
if (!Fd->OpenDescriptor(fd, FileFd::ReadWrite, FileFd::None, true))
{
_error->Errno("GetTempFile",_("Unable to write to %s"),fn);
- return NULL;
+ if (TmpFd == nullptr)
+ delete Fd;
+ return nullptr;
}
return Fd;
}