diff options
| author | Julian Andres Klode <jak@debian.org> | 2009-07-10 18:06:41 +0200 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2009-07-10 18:06:41 +0200 |
| commit | c0818a4cdadb30ccb2ea9d63a6e81fa1a39394d6 (patch) | |
| tree | f645e65c525c686718f40511b7ddde1cb716d843 /python | |
| parent | 7d12f1ce6bc839f27604782bc712a0ccb481f2b2 (diff) | |
| download | python-apt-c0818a4cdadb30ccb2ea9d63a6e81fa1a39394d6.tar.gz | |
python/indexrecords.cc: Correctly Decrease refcount for HashString.
Create a copy of the HashString() and create a CppPyObject for it. After
adding it to the tuple, decrease the reference count. The HashString()
copy allows us to deallocate the indexRecords and does not require the
PyHashString objects to be CppOwnedPyObject.
Diffstat (limited to 'python')
| -rw-r--r-- | python/indexrecords.cc | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/python/indexrecords.cc b/python/indexrecords.cc index 588cf883..9ab052f6 100644 --- a/python/indexrecords.cc +++ b/python/indexrecords.cc @@ -58,9 +58,12 @@ static PyObject *IndexRecords_Lookup(PyObject *self,PyObject *args) PyErr_SetString(PyExc_KeyError,keyname); return 0; } - return Py_BuildValue("(Oi)", - PyHashString_FromCpp((HashString*)&result->Hash), - result->Size); + // Copy the HashString(), to prevent crashes and to not require the + // indexRecords object to exist. + PyObject *py_hash = PyHashString_FromCpp(new HashString(result->Hash)); + PyObject *value = Py_BuildValue("(Oi)",py_hash,result->Size); + Py_DECREF(py_hash); + return value; } static PyObject *IndexRecords_GetDist(PyObject *self) |
