Bug#151489: python-apt: fixed the big leak, but there is something left.
Package: python-apt
Version: 0.5.4.3
Followup-For: Bug #151489
Tags: patch
I attach a patch to python-apt which fixes the big leak by keeping
track of and deleting the PkgCacheFile objects.
However there is still some other small memory leak, here some stats:
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.
sources: deb http://ftp.uk.debian.org/debian/ sid contrib
2300 iterations (load, unload)
leak 360KB (3676-4036) in increments of 36 kB
0.15KB per iteration.
Attached also goes the python script I used to get the above data.
Thanks,
ranty
-- System Information
Debian Release: 3.0
Architecture: i386
Kernel: Linux hell 2.4.18-ac3 #4 Fri Apr 26 11:17:02 CEST 2002 i686
Locale: LANG=C, LC_CTYPE=es_ES
Versions of packages python-apt depends on:
ii apt [libapt-pkg-libc6.2-3-2-3 0.5.4 Advanced front-end for dpkg
ii apt-utils [libapt-inst-libc6. 0.5.4 APT utility programs
ii libc6 2.2.5-7 GNU C Library: Shared libraries an
ii python 2.1.3-3 An interactive object-oriented scr
-- no debconf information
diff -urN python-apt-0.5.4.3/python/cache.cc python-apt-0.5.4.3-mine/python/cache.cc
--- python-apt-0.5.4.3/python/cache.cc Tue Feb 26 02:36:15 2002
+++ python-apt-0.5.4.3-mine/python/cache.cc Mon Jul 1 11:29:26 2002
@@ -66,7 +66,8 @@
// ---------------------------------------------------------------------
static PyObject *CacheAttr(PyObject *Self,char *Name)
{
- pkgCache *Cache = GetCpp<pkgCache *>(Self);
+ pkgCacheFile *CacheFile = GetCpp<pkgCacheFile *>(Self);
+ pkgCache *Cache = (pkgCache *)(*CacheFile);
if (strcmp("Packages",Name) == 0)
return CppOwnedPyObject_NEW<PkgListStruct>(Self,&PkgListType,Cache->PkgBegin());
@@ -102,7 +103,8 @@
// Map access, operator []
static PyObject *CacheMapOp(PyObject *Self,PyObject *Arg)
{
- pkgCache *Cache = GetCpp<pkgCache *>(Self);
+ pkgCacheFile *CacheFile = GetCpp<pkgCacheFile *>(Self);
+ pkgCache *Cache = (pkgCache *)(*CacheFile);
if (PyString_Check(Arg) == 0)
{
@@ -121,6 +123,16 @@
return CppOwnedPyObject_NEW<pkgCache::PkgIterator>(Self,&PackageType,Pkg);
}
+static void CppOwnedDealloc_pkgCache(PyObject *iObj)
+{
+ pkgCacheFile *CacheFile = GetCpp<pkgCacheFile *>(iObj);
+ pkgCache *Cache = (pkgCache *)(*CacheFile);
+ CacheFile->Close();
+ delete CacheFile;
+ CppOwnedDealloc<pkgCacheFile *>(iObj);
+}
+
+
static PyMappingMethods CacheMap = {0,CacheMapOp,0};
PyTypeObject PkgCacheType =
@@ -128,10 +140,10 @@
PyObject_HEAD_INIT(&PyType_Type)
0, // ob_size
"pkgCache", // tp_name
- sizeof(CppOwnedPyObject<pkgCache *>), // tp_basicsize
+ sizeof(CppOwnedPyObject<pkgCacheFile *>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppOwnedDealloc<pkgCache *>, // tp_dealloc
+ CppOwnedDealloc_pkgCache, // tp_dealloc
0, // tp_print
CacheAttr, // tp_getattr
0, // tp_setattr
@@ -722,10 +734,10 @@
if (PyArg_ParseTuple(Args,"") == 0)
return 0;
- pkgCacheFile *Cache = new pkgCacheFile();
+ pkgCacheFile *CacheFile = new pkgCacheFile();
OpTextProgress Prog;
- if (Cache->Open(Prog,false) == false)
+ if (CacheFile->Open(Prog,false) == false)
return HandleErrors();
- return CppOwnedPyObject_NEW<pkgCache *>(0,&PkgCacheType,(pkgCache *)(*Cache));
+ return CppOwnedPyObject_NEW<pkgCacheFile *>(0,&PkgCacheType,CacheFile);
}
diff -urN python-apt-0.5.4.3/python/pkgrecords.cc python-apt-0.5.4.3-mine/python/pkgrecords.cc
--- python-apt-0.5.4.3/python/pkgrecords.cc Tue Feb 26 02:36:15 2002
+++ python-apt-0.5.4.3-mine/python/pkgrecords.cc Mon Jul 1 11:48:48 2002
@@ -11,6 +11,7 @@
#include "generic.h"
#include "apt_pkgmodule.h"
+#include <apt-pkg/cachefile.h>
#include <apt-pkg/pkgrecords.h>
#include <Python.h>
@@ -22,6 +23,8 @@
pkgRecords::Parser *Last;
PkgRecordsStruct(pkgCache *Cache) : Records(*Cache), Last(0) {};
+ PkgRecordsStruct(pkgCacheFile *CacheFile)
+ : Records(*(pkgCache *)(*CacheFile)), Last(0) {};
PkgRecordsStruct() : Records(*(pkgCache *)0) {abort();}; // G++ Bug..
};
@@ -113,6 +116,6 @@
return 0;
return HandleErrors(CppOwnedPyObject_NEW<PkgRecordsStruct>(Owner,&PkgRecordsType,
- GetCpp<pkgCache *>(Owner)));
+ GetCpp<pkgCacheFile *>(Owner)));
}
#!/usr/bin/env python
import apt_pkg
import os
apt_pkg.InitConfig()
apt_pkg.InitSystem()
count = 0
while 1:
cache = apt_pkg.GetCache()
cache = None
os.system("ps --format=vsize %d |grep -v VSZ"%(os.getpid()))
count += 1
print '\t%d'%(count)
Reply to: