summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJulian Andres Klode <jak@debian.org>2009-06-12 18:56:23 +0200
committerJulian Andres Klode <jak@debian.org>2009-06-12 18:56:23 +0200
commit395b33f9f8e93223f933c625bacbf1e2d23c6673 (patch)
tree08d5853f0add0a0ca0c35db547a18709749172fb /python
parentaa31a066174571a64e68c35203f6b2404ef2393f (diff)
downloadpython-apt-395b33f9f8e93223f933c625bacbf1e2d23c6673.tar.gz
Bugfix: Delete pointers correctly, fixing memory leaks. (LP: #370149)
We previously called the destructor of the pointer. This resulted in no object using pointers being deallocated. This patch introduces CppDeallocPtr() and CppOwnedDeallocPtr() which do the same as the other CppDealloc() and CppOwnedDealloc(), but use 'delete' on the pointer instead of the deconstructor. Furthermore, this patch also changes AcquireFile to be a CppOwnedPyObject, owned by the Acquire object. Without this change, deleting the Acquire object would cause a crash when AcquireFile is deallocated.
Diffstat (limited to 'python')
-rw-r--r--python/acquire.cc8
-rw-r--r--python/cache.cc4
-rw-r--r--python/depcache.cc6
-rw-r--r--python/generic.h19
-rw-r--r--python/hashstring.cc2
-rw-r--r--python/indexfile.cc2
-rw-r--r--python/indexrecords.cc2
-rw-r--r--python/metaindex.cc2
-rw-r--r--python/pkgmanager.cc2
-rw-r--r--python/policy.cc2
-rw-r--r--python/sourcelist.cc2
11 files changed, 35 insertions, 16 deletions
diff --git a/python/acquire.cc b/python/acquire.cc
index 702d48ce..6b091479 100644
--- a/python/acquire.cc
+++ b/python/acquire.cc
@@ -261,7 +261,7 @@ PyTypeObject PkgAcquireType =
sizeof(CppPyObject<pkgAcquire*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppDealloc<pkgAcquire*>, // tp_dealloc
+ CppDeallocPtr<pkgAcquire*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
@@ -329,7 +329,7 @@ static PyObject *PkgAcquireFileNew(PyTypeObject *type, PyObject *Args, PyObject
shortDescr,
destDir,
destFile); // short-desc
- CppPyObject<pkgAcqFile*> *AcqFileObj = CppPyObject_NEW<pkgAcqFile*>(type);
+ CppOwnedPyObject<pkgAcqFile*> *AcqFileObj = CppOwnedPyObject_NEW<pkgAcqFile*>(pyfetcher, type);
AcqFileObj->Object = af;
return AcqFileObj;
@@ -349,10 +349,10 @@ PyTypeObject PkgAcquireFileType =
0, // ob_size
#endif
"apt_pkg.AcquireFile", // tp_name
- sizeof(CppPyObject<pkgAcqFile*>),// tp_basicsize
+ sizeof(CppOwnedPyObject<pkgAcqFile*>),// tp_basicsize
0, // tp_itemsize
// Methods
- CppDealloc<pkgAcqFile*>, // tp_dealloc
+ CppOwnedDeallocPtr<pkgAcqFile*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
diff --git a/python/cache.cc b/python/cache.cc
index 14484104..22ed9ecc 100644
--- a/python/cache.cc
+++ b/python/cache.cc
@@ -247,7 +247,7 @@ void PkgCacheFileDealloc(PyObject *Self)
PyObject *CacheFilePy = GetOwner<pkgCache*>(Self);
pkgCacheFile *CacheF = GetCpp<pkgCacheFile*>(CacheFilePy);
CacheF->Close();
- CppOwnedDealloc<pkgCache *>(Self);
+ CppOwnedDeallocPtr<pkgCache *>(Self);
}
static PyObject *PkgCacheNew(PyTypeObject *type,PyObject *Args,PyObject *kwds)
@@ -365,7 +365,7 @@ PyTypeObject PkgCacheFileType =
sizeof(CppOwnedPyObject<pkgCacheFile*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppOwnedDealloc<pkgCacheFile*>, // tp_dealloc
+ CppOwnedDeallocPtr<pkgCacheFile*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
diff --git a/python/depcache.cc b/python/depcache.cc
index f1c34fef..9bbda527 100644
--- a/python/depcache.cc
+++ b/python/depcache.cc
@@ -660,7 +660,7 @@ PyTypeObject PkgDepCacheType =
sizeof(CppOwnedPyObject<pkgDepCache *>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppOwnedDealloc<pkgDepCache *>, // tp_dealloc
+ CppOwnedDeallocPtr<pkgDepCache *>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
@@ -844,7 +844,7 @@ PyTypeObject PkgProblemResolverType =
sizeof(CppOwnedPyObject<pkgProblemResolver *>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppOwnedDealloc<pkgProblemResolver *>, // tp_dealloc
+ CppOwnedDeallocPtr<pkgProblemResolver *>,// tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
@@ -962,7 +962,7 @@ PyTypeObject PkgActionGroupType =
sizeof(CppOwnedPyObject<pkgDepCache::ActionGroup*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppOwnedDealloc<pkgDepCache::ActionGroup*>, // tp_dealloc
+ CppOwnedDeallocPtr<pkgDepCache::ActionGroup*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
diff --git a/python/generic.h b/python/generic.h
index df4d8755..b7b958f5 100644
--- a/python/generic.h
+++ b/python/generic.h
@@ -153,6 +153,25 @@ void CppOwnedDealloc(PyObject *iObj)
iObj->ob_type->tp_free(iObj);
}
+// Pointer deallocation
+// Generic Dealloc type functions
+template <class T>
+void CppDeallocPtr(PyObject *Obj)
+{
+ delete GetCpp<T>(Obj);
+ Obj->ob_type->tp_free(Obj);
+}
+
+template <class T>
+void CppOwnedDeallocPtr(PyObject *iObj)
+{
+ CppOwnedPyObject<T> *Obj = (CppOwnedPyObject<T> *)iObj;
+ delete Obj->Object;
+ if (Obj->Owner != 0)
+ Py_DECREF(Obj->Owner);
+ iObj->ob_type->tp_free(iObj);
+}
+
inline PyObject *CppPyString(std::string Str)
{
return PyString_FromStringAndSize(Str.c_str(),Str.length());
diff --git a/python/hashstring.cc b/python/hashstring.cc
index 58bcca9e..23212a4b 100644
--- a/python/hashstring.cc
+++ b/python/hashstring.cc
@@ -103,7 +103,7 @@ PyTypeObject PyHashString_Type = {
sizeof(CppPyObject<HashString*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppDealloc<HashString*>, // tp_dealloc
+ CppDeallocPtr<HashString*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
diff --git a/python/indexfile.cc b/python/indexfile.cc
index 795931fb..78a4f513 100644
--- a/python/indexfile.cc
+++ b/python/indexfile.cc
@@ -99,7 +99,7 @@ PyTypeObject PackageIndexFileType =
sizeof(CppOwnedPyObject<pkgIndexFile*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppOwnedDealloc<pkgIndexFile*>, // tp_dealloc
+ CppOwnedDeallocPtr<pkgIndexFile*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
diff --git a/python/indexrecords.cc b/python/indexrecords.cc
index 61ff07fc..fcb2b85d 100644
--- a/python/indexrecords.cc
+++ b/python/indexrecords.cc
@@ -89,7 +89,7 @@ PyTypeObject PyIndexRecords_Type = {
sizeof(CppPyObject<indexRecords*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppDealloc<indexRecords*>, // tp_dealloc
+ CppDeallocPtr<indexRecords*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
diff --git a/python/metaindex.cc b/python/metaindex.cc
index b451f0b5..b5d194b4 100644
--- a/python/metaindex.cc
+++ b/python/metaindex.cc
@@ -80,7 +80,7 @@ PyTypeObject MetaIndexType =
sizeof(CppOwnedPyObject<metaIndex*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppOwnedDealloc<metaIndex*>, // tp_dealloc
+ CppOwnedDeallocPtr<metaIndex*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
diff --git a/python/pkgmanager.cc b/python/pkgmanager.cc
index f47e77ad..0fd2cd92 100644
--- a/python/pkgmanager.cc
+++ b/python/pkgmanager.cc
@@ -138,7 +138,7 @@ PyTypeObject PkgManagerType =
sizeof(CppPyObject<pkgPackageManager*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppDealloc<pkgPackageManager*>, // tp_dealloc
+ CppDeallocPtr<pkgPackageManager*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
diff --git a/python/policy.cc b/python/policy.cc
index 89604e9a..992a1192 100644
--- a/python/policy.cc
+++ b/python/policy.cc
@@ -151,7 +151,7 @@ PyTypeObject PyPolicy_Type = {
sizeof(CppOwnedPyObject<pkgPolicy*>),// tp_basicsize
0, // tp_itemsize
// Methods
- CppOwnedDealloc<pkgPolicy*>, // tp_dealloc
+ CppOwnedDeallocPtr<pkgPolicy*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
diff --git a/python/sourcelist.cc b/python/sourcelist.cc
index 5e5838d8..e53fccd3 100644
--- a/python/sourcelist.cc
+++ b/python/sourcelist.cc
@@ -123,7 +123,7 @@ PyTypeObject PkgSourceListType =
sizeof(CppPyObject<pkgSourceList*>), // tp_basicsize
0, // tp_itemsize
// Methods
- CppDealloc<pkgSourceList*>, // tp_dealloc
+ CppDeallocPtr<pkgSourceList*>, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr