diff options
| author | Michael Vogt <michael.vogt@ubuntu.com> | 2006-01-11 11:27:18 +0000 |
|---|---|---|
| committer | Michael Vogt <michael.vogt@ubuntu.com> | 2006-01-11 11:27:18 +0000 |
| commit | ff33c888f56a00e3dea542cfb1091be3585311c8 (patch) | |
| tree | 767b94cd99578e7d229850f6a9bb8a207e49534c /python/cache.cc | |
| parent | 38efee6ebac24314f3e0284fd1f551aac22a5bfa (diff) | |
| download | python-apt-ff33c888f56a00e3dea542cfb1091be3585311c8.tar.gz | |
* make sure to close the CacheFile when a pkgCache is deallocated
Diffstat (limited to 'python/cache.cc')
| -rw-r--r-- | python/cache.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/python/cache.cc b/python/cache.cc index 5e2d9819..b35a3ade 100644 --- a/python/cache.cc +++ b/python/cache.cc @@ -231,6 +231,17 @@ static PyObject *CacheMapOp(PyObject *Self,PyObject *Arg) return CppOwnedPyObject_NEW<pkgCache::PkgIterator>(Self,&PackageType,Pkg); } +// we need a special dealloc here to make sure that the CacheFile +// is closed before deallocation the cache (otherwise we have a bad) +// memory leak +void PkgCacheFileDealloc(PyObject *Self) +{ + PyObject *CacheFilePy = GetOwner<pkgCache*>(Self); + pkgCacheFile *CacheF = GetCpp<pkgCacheFile*>(CacheFilePy); + CacheF->Close(); + CppOwnedDealloc<pkgCache *>(Self); +} + static PyMappingMethods CacheMap = {0,CacheMapOp,0}; PyTypeObject PkgCacheType = { @@ -240,7 +251,7 @@ PyTypeObject PkgCacheType = sizeof(CppOwnedPyObject<pkgCache *>), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc<pkgCache *>, // tp_dealloc + PkgCacheFileDealloc, // tp_dealloc 0, // tp_print CacheAttr, // tp_getattr 0, // tp_setattr |
