diff options
| author | Julian Andres Klode <julian.klode@canonical.com> | 2025-01-13 19:29:06 +0100 |
|---|---|---|
| committer | Julian Andres Klode <julian.klode@canonical.com> | 2025-02-14 19:45:12 +0100 |
| commit | 18022c4a71ded214d69822d52804ce9344a9b65e (patch) | |
| tree | 11e80c2db2f59a8a911fc16db4550813ca33e1f7 /apt-pkg | |
| parent | 2666b0eb1cea31d92f89f1832f6efc5cc8a3f97f (diff) | |
policy: Use smart pointers
Diffstat (limited to 'apt-pkg')
| -rw-r--r-- | apt-pkg/policy.cc | 15 | ||||
| -rw-r--r-- | 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<signed short[]>(Owner->Head().PackageFileCount); + VerPins = std::make_unique<Pin[]>(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<Pin[]> VerPins; + std::unique_ptr<signed short[]> PFPriority; std::vector<Pin> Defaults; std::vector<PkgPin> 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<Private> const d; }; APT_PUBLIC bool ReadPinFile(pkgPolicy &Plcy, std::string File = ""); |
