diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-06-12 18:56:23 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-06-12 18:56:23 +0200 |
| commit | 395b33f9f8e93223f933c625bacbf1e2d23c6673 (patch) | |
| tree | 08d5853f0add0a0ca0c35db547a18709749172fb /python/generic.h | |
| parent | aa31a066174571a64e68c35203f6b2404ef2393f (diff) | |
| download | python-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/generic.h')
| -rw-r--r-- | python/generic.h | 19 |
1 files changed, 19 insertions, 0 deletions
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()); |
