From ff33c888f56a00e3dea542cfb1091be3585311c8 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 11 Jan 2006 11:27:18 +0000 Subject: * make sure to close the CacheFile when a pkgCache is deallocated --- python/cache.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'python/cache.cc') 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(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(Self); + pkgCacheFile *CacheF = GetCpp(CacheFilePy); + CacheF->Close(); + CppOwnedDealloc(Self); +} + static PyMappingMethods CacheMap = {0,CacheMapOp,0}; PyTypeObject PkgCacheType = { @@ -240,7 +251,7 @@ PyTypeObject PkgCacheType = sizeof(CppOwnedPyObject), // tp_basicsize 0, // tp_itemsize // Methods - CppOwnedDealloc, // tp_dealloc + PkgCacheFileDealloc, // tp_dealloc 0, // tp_print CacheAttr, // tp_getattr 0, // tp_setattr -- cgit v1.2.3