Re: Bug#151489: python-apt: fixed the big leak, but there is something left.
On Mon, 1 Jul 2002, Manuel Estrada Sainz wrote:
> I attach a patch to python-apt which fixes the big leak by keeping
> track of and deleting the PkgCacheFile objects.
Yes, this particular leak is why the GetCache method is called
TmpGetCache.. It wasn't ment to be a completely correct solution..
Your patch isn't entirely great.. The pkgcache py-wrapper should not be
changed. It was ment to be as it is. The problem is that TmpGetCache
doesn't create a PkgCacheFile pyobject to hold the reference to that
class. It should do that and attach it to via the Owned mechanism to the
PkgCache object it returns.
> sources: deb http://ftp.uk.debian.org/debian/ sid main non-free contrib
> 1200 iterations (load, unload)
> leak 528KB (3676-4204) in increments of 36 kB
> 0.44KB per iteration.
Hmm, wonder what this is..
Ah, yes, the soruce list is leaking. tsk. Attached patch will fix that.
Jason
? leak.diff
Index: sourcelist.cc
===================================================================
RCS file: /cvs/deity/apt/apt-pkg/sourcelist.cc,v
retrieving revision 1.22
diff -u -r1.22 sourcelist.cc
--- sourcelist.cc 2002/03/26 07:38:58 1.22
+++ sourcelist.cc 2002/07/01 21:40:34
@@ -128,6 +128,18 @@
Read(File);
}
/*}}}*/
+// SourceList::~pkgSourceList - Destructor /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgSourceList::~pkgSourceList()
+{
+ for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++)
+ delete *I;
+ for (vector<Vendor const *>::const_iterator I = VendorList.begin();
+ I != VendorList.end(); I++)
+ delete *I;
+}
+ /*}}}*/
// SourceList::ReadVendors - Read list of known package vendors /*{{{*/
// ---------------------------------------------------------------------
/* This also scans a directory of vendor files similar to apt.conf.d
@@ -147,6 +159,11 @@
if (ReadConfigFile(Cnf,CnfFile,true) == false)
return false;
+ for (vector<Vendor const *>::const_iterator I = VendorList.begin();
+ I != VendorList.end(); I++)
+ delete *I;
+ VendorList.erase(VendorList.begin(),VendorList.end());
+
// Process 'simple-key' type sections
const Configuration::Item *Top = Cnf.Tree("simple-key");
for (Top = (Top == 0?0:Top->Child); Top != 0; Top = Top->Next)
@@ -217,6 +234,8 @@
if (!F != 0)
return _error->Errno("ifstream::ifstream",_("Opening %s"),File.c_str());
+ for (const_iterator I = SrcList.begin(); I != SrcList.end(); I++)
+ delete *I;
SrcList.erase(SrcList.begin(),SrcList.end());
char Buffer[300];
Index: sourcelist.h
===================================================================
RCS file: /cvs/deity/apt/apt-pkg/sourcelist.h,v
retrieving revision 1.11
diff -u -r1.11 sourcelist.h
--- sourcelist.h 2001/05/07 04:24:08 1.11
+++ sourcelist.h 2002/07/01 21:40:34
@@ -106,7 +106,8 @@
bool GetIndexes(pkgAcquire *Owner) const;
pkgSourceList();
- pkgSourceList(string File);
+ pkgSourceList(string File);
+ ~pkgSourceList();
};
#endif
Reply to: