From e79f9bb22375fd72330b534e17dcd3ceace432e8 Mon Sep 17 00:00:00 2001 From: Herman Semenoff Date: Wed, 8 Apr 2026 13:09:52 +0300 Subject: apt-pkg: methods: fixed many minor memleaks Static analysis has shown that there are many minor memleaks. --- apt-pkg/contrib/cdromutl.cc | 1 + apt-pkg/dirstream.cc | 1 + apt-pkg/indexcopy.cc | 1 + apt-pkg/pkgsystem.cc | 5 ++++- methods/connect.cc | 3 +++ 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/apt-pkg/contrib/cdromutl.cc b/apt-pkg/contrib/cdromutl.cc index ff8fb4835..60d137930 100644 --- a/apt-pkg/contrib/cdromutl.cc +++ b/apt-pkg/contrib/cdromutl.cc @@ -255,6 +255,7 @@ bool IdentCdrom(string CD,string &Res,unsigned int Version) closedir(D); Res = Hash.GetHashString(Hashes::MD5SUM).HashValue().append(std::move(S)); + close(dirfd); return true; } /*}}}*/ diff --git a/apt-pkg/dirstream.cc b/apt-pkg/dirstream.cc index ef9f08ebc..b71a34d3e 100644 --- a/apt-pkg/dirstream.cc +++ b/apt-pkg/dirstream.cc @@ -53,6 +53,7 @@ bool pkgDirStream::DoItem(Item &Itm,int &Fd) return _error->Errno("fchown",_("Failed to write file %s"), Itm.Name); } Fd = iFd; + close(iFd); return true; } diff --git a/apt-pkg/indexcopy.cc b/apt-pkg/indexcopy.cc index 089bfd2ce..636393dd6 100644 --- a/apt-pkg/indexcopy.cc +++ b/apt-pkg/indexcopy.cc @@ -573,6 +573,7 @@ bool SigVerify::CopyAndVerify(string CDROM,string Name,vector &SigList, pid_t pid = ExecFork(); if(pid < 0) { _error->Error("Fork failed"); + delete MetaIndex; return false; } if(pid == 0) diff --git a/apt-pkg/pkgsystem.cc b/apt-pkg/pkgsystem.cc index 7e48a68c7..4bc05d19b 100644 --- a/apt-pkg/pkgsystem.cc +++ b/apt-pkg/pkgsystem.cc @@ -69,4 +69,7 @@ map_id_t pkgSystem::GetVersionMapping(map_id_t const in) const return (o == d->idmap.end()) ? in : o->second; } /*}}}*/ -pkgSystem::~pkgSystem() {} +pkgSystem::~pkgSystem() +{ + delete d; +} diff --git a/methods/connect.cc b/methods/connect.cc index 828be3f50..7e740e398 100644 --- a/methods/connect.cc +++ b/methods/connect.cc @@ -1011,7 +1011,10 @@ ResultState UnwrapTLS(std::string const &Host, std::unique_ptr &Fd, if (auto ctx = GetContextForHost(Host, OwnerConf)) tlsFd->ssl = SSL_new(ctx); else + { + delete tlsFd; return ResultState::FATAL_ERROR; + } FdFd *fdfd = dynamic_cast(Fd.get()); if (fdfd != nullptr) -- cgit v1.2.3-70-g09d2