From 18022c4a71ded214d69822d52804ce9344a9b65e Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Mon, 13 Jan 2025 19:29:06 +0100 Subject: policy: Use smart pointers --- apt-pkg/policy.cc | 15 +++++---------- apt-pkg/policy.h | 6 +++--- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/apt-pkg/policy.cc b/apt-pkg/policy.cc index a54f04db6..ab21cd039 100644 --- a/apt-pkg/policy.cc +++ b/apt-pkg/policy.cc @@ -57,8 +57,8 @@ pkgPolicy::pkgPolicy(pkgCache *Owner) : VerPins(nullptr), { if (Owner == 0) return; - PFPriority = new signed short[Owner->Head().PackageFileCount]; - VerPins = new Pin[Owner->Head().VersionCount]; + PFPriority = std::make_unique(Owner->Head().PackageFileCount); + VerPins = std::make_unique(Owner->Head().VersionCount); auto VersionCount = Owner->Head().VersionCount; for (decltype(VersionCount) I = 0; I != VersionCount; ++I) @@ -237,7 +237,7 @@ void pkgPolicy::CreatePin(pkgVersionMatch::MatchType Type,string Name, // Find matching version(s) and copy the pin into it pkgVersionMatch Match(P.Data,P.Type); if (Match.VersionMatches(Ver)) { - Pin *VP = VerPins + Ver->ID; + Pin *VP = &VerPins[Ver->ID]; if (VP->Type == pkgVersionMatch::None) { *VP = P; matched = true; @@ -260,7 +260,7 @@ void pkgPolicy::CreatePin(pkgVersionMatch::MatchType Type,string Name, for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() != true; ++Ver) { if (Match.VersionMatches(Ver)) { - Pin *VP = VerPins + Ver->ID; + Pin *VP = &VerPins[Ver->ID]; if (VP->Type == pkgVersionMatch::None) { *VP = P; matched = true; @@ -503,9 +503,4 @@ bool ReadPinFile(pkgPolicy &Plcy,string File) } /*}}}*/ -pkgPolicy::~pkgPolicy() -{ - delete[] PFPriority; - delete[] VerPins; - delete d; -} +pkgPolicy::~pkgPolicy() = default; diff --git a/apt-pkg/policy.h b/apt-pkg/policy.h index 3a377fe25..36c32b644 100644 --- a/apt-pkg/policy.h +++ b/apt-pkg/policy.h @@ -58,8 +58,8 @@ class APT_PUBLIC pkgPolicy : public pkgDepCache::Policy explicit PkgPin(std::string const &Pkg) : Pin(), Pkg(Pkg) {}; }; - Pin *VerPins; - signed short *PFPriority; + std::unique_ptr VerPins; + std::unique_ptr PFPriority; std::vector Defaults; std::vector Unmatched; pkgCache *Cache; @@ -84,7 +84,7 @@ class APT_PUBLIC pkgPolicy : public pkgDepCache::Policy virtual ~pkgPolicy(); private: struct Private; - Private *const d; + std::unique_ptr const d; }; APT_PUBLIC bool ReadPinFile(pkgPolicy &Plcy, std::string File = ""); -- cgit v1.2.3-70-g09d2