From dcbbb14df8c9a8a146697720874e9425c4b33792 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 10 Jun 2015 22:10:48 +0200 Subject: stop using IndexTarget pointers which are never freed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creating and passing around a bunch of pointers of IndexTargets (and of a vector of pointers of IndexTargets) is probably done to avoid the 'costly' copy of container, but we are really not in a timecritical operation here and move semantics will help us even further in the future. On the other hand we never do a proper cleanup of these pointers, which is very dirty, even if structures aren't that big… The changes will effecting many items only effect our own hidden class, so we can do that without fearing breaking interfaces or anything. Git-Dch: Ignore --- apt-pkg/deb/debmetaindex.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'apt-pkg/deb/debmetaindex.cc') diff --git a/apt-pkg/deb/debmetaindex.cc b/apt-pkg/deb/debmetaindex.cc index f038f12f5..44d66a725 100644 --- a/apt-pkg/deb/debmetaindex.cc +++ b/apt-pkg/deb/debmetaindex.cc @@ -93,7 +93,7 @@ debReleaseIndex::~debReleaseIndex() { template void foreachTarget(std::string const URI, std::string const Dist, std::map > const &ArchEntries, - CallC Call) + CallC &Call) { bool const flatArchive = (Dist[Dist.length() - 1] == '/'); std::string baseURI = URI; @@ -206,7 +206,7 @@ void foreachTarget(std::string const URI, std::string const Dist, struct ComputeIndexTargetsClass { - vector * const IndexTargets; + vector IndexTargets; void operator()(std::string MetaKey, std::string ShortDesc, std::string LongDesc, bool const IsOptional, std::map Options) @@ -217,7 +217,7 @@ struct ComputeIndexTargetsClass ShortDesc = SubstVar(ShortDesc, std::string("$(") + O->first + ")", O->second); LongDesc = SubstVar(LongDesc, std::string("$(") + O->first + ")", O->second); } - IndexTarget * Target = new IndexTarget( + IndexTarget Target( MetaKey, ShortDesc, LongDesc, @@ -225,13 +225,11 @@ struct ComputeIndexTargetsClass IsOptional, Options ); - IndexTargets->push_back(Target); + IndexTargets.push_back(Target); } - - ComputeIndexTargetsClass() : IndexTargets(new vector ) {} }; -vector * debReleaseIndex::ComputeIndexTargets() const +std::vector debReleaseIndex::ComputeIndexTargets() const { ComputeIndexTargetsClass comp; foreachTarget(URI, Dist, ArchEntries, comp); @@ -249,7 +247,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const iR->SetTrusted(false); // special case for --print-uris - vector const * const targets = ComputeIndexTargets(); + std::vector const targets = ComputeIndexTargets(); #define APT_TARGET(X) IndexTarget("", X, MetaIndexInfo(X), MetaIndexURI(X), false, std::map()) pkgAcqMetaBase * const TransactionManager = new pkgAcqMetaClearSig(Owner, APT_TARGET("InRelease"), APT_TARGET("Release"), APT_TARGET("Release.gpg"), @@ -257,7 +255,7 @@ bool debReleaseIndex::GetIndexes(pkgAcquire *Owner, bool const &GetAll) const #undef APT_TARGET if (GetAll) { - for (vector ::const_iterator Target = targets->begin(); Target != targets->end(); ++Target) + for (std::vector::const_iterator Target = targets.begin(); Target != targets.end(); ++Target) new pkgAcqIndex(Owner, TransactionManager, *Target); } -- cgit v1.2.3