From c0818a4cdadb30ccb2ea9d63a6e81fa1a39394d6 Mon Sep 17 00:00:00 2001 From: Julian Andres Klode Date: Fri, 10 Jul 2009 18:06:41 +0200 Subject: 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. --- python/indexrecords.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'python/indexrecords.cc') 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) -- cgit v1.2.3