Re: memory leak in python bindings
Jack Diederich <[email protected]> Tue, 3 Oct 2006 15:06:36 -0400
| Newsgroups | gmane.comp.db.metakit |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Oct 02, 2006 at 05:52:29PM -0700, Brian Warner wrote:
>
> Hi all..
>
> I spent some time a few weeks ago tracking down a memory leak in the metakit
> python bindings. I've come up with a patch which seems to fix the issue.. I'm
> hoping that someone with more experience with the code than me could take a
> look at it and consider applying it upstream.
>
<snip>
> --- old-metakit-2.4.9.5/python/scxx/PWOMapping.h 2006-08-09 00:18:33.000000000 -0700
> +++ new-metakit-2.4.9.5/python/scxx/PWOMapping.h 2006-08-09 00:18:33.000000000 -0700
> @@ -55,9 +59,11 @@
> //PyMapping_GetItemString
> //PyDict_GetItemString
> PWOMappingMmbr operator [] (const char* key) {
> + // note: this PyMapping call creates a new reference
> PyObject* rslt = PyMapping_GetItemString(_obj, (char*) key);
> if (rslt == NULL)
> PyErr_Clear();
> + Py_XDECREF(rslt); // PWOMappingMmbr claims its own refcnt, so decref now
> PWOString _key(key);
> return PWOMappingMmbr(rslt, *this, _key);
> };
Looks good to me. I tried looking for similar refleaks but
quickly got lost between the PyMapping_* calls and the PyDict_*
calls (PyDict_* calls generally steal references, the abstract
interface doesn't). I think the _obj member must always be a
PyDict or there would be a lot of core dumping going on.
-Jack
_____________________________________________
Metakit mailing list - [email protected]
http://www.equi4.com/mailman/listinfo/metakit