diff options
author | David Kalnischkies <david@kalnischkies.de> | 2021-03-09 11:40:35 +0100 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2021-03-09 13:38:13 +0100 |
commit | 302b1edcb1afe8098ddc2ddd576e56b898c1d90b (patch) | |
tree | 934b2def5c8cf231ab248eec39699ca8eeb9ef6f | |
parent | 3312607159410eda3c634a0c6fe3c2b1a4fd3cc3 (diff) |
Handle multi-arch pkgnames for dpkg call via RAII
-rw-r--r-- | apt-pkg/deb/dpkgpm.cc | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc index ba5c3a11a..bdaa353c5 100644 --- a/apt-pkg/deb/dpkgpm.cc +++ b/apt-pkg/deb/dpkgpm.cc @@ -1758,8 +1758,6 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) auto Size = StartSize; Args.erase(Args.begin() + BaseArgs, Args.end()); Args.reserve(size); - // keep track of allocated strings for multiarch package names - std::vector<char *> Packages(size, nullptr); int fd[2]; if (pipe(fd) != 0) @@ -1827,6 +1825,9 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) } std::unique_ptr<char, decltype(&cleanUpTmpDir)> tmpdir_for_dpkg_recursive{nullptr, &cleanUpTmpDir}; + // keep track of allocated strings for multiarch package names + std::vector<std::unique_ptr<char, decltype(std::free) *>> Packages; + Packages.reserve(size); // Write in the file or package names if (I->Op == Item::Install) @@ -1934,8 +1935,8 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) name.append(":").append(PkgVer.Arch()); else _error->Warning("Can not find PkgVer for '%s'", name.c_str()); - Packages.push_back(strdup(name.c_str())); - AddArg(Packages.back()); + Packages.emplace_back(strdup(name.c_str()), &std::free); + AddArg(Packages.back().get()); } } // skip configure action if all scheduled packages disappeared @@ -1951,10 +1952,6 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) a != Args.end(); ++a) clog << *a << ' '; clog << endl; - for (std::vector<char *>::const_iterator p = Packages.begin(); - p != Packages.end(); ++p) - free(*p); - Packages.clear(); close(fd[0]); close(fd[1]); continue; @@ -2045,9 +2042,6 @@ bool pkgDPkgPM::Go(APT::Progress::PackageManager *progress) sigprocmask(SIG_BLOCK,&d->sigmask,&d->original_sigmask); /* free vectors (and therefore memory) as we don't need the included data anymore */ - for (std::vector<char *>::const_iterator p = Packages.begin(); - p != Packages.end(); ++p) - free(*p); Packages.clear(); // the result of the waitpid call |