From e3d8dc8559067ccbe5689c877af4fd53d84cb0eb Mon Sep 17 00:00:00 2001 From: Graham Dumpleton Date: Thu, 19 Sep 2013 22:15:44 +1000 Subject: [PATCH] Memory leak in C implementation of object proxy when instance method called via class and instance passed in explicitly. --- docs/changes.rst | 5 +++++ src/_wrappers.c | 10 ++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/changes.rst b/docs/changes.rst index d650557..37b4101 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -6,6 +6,11 @@ Version 1.2.0 **Bugs Fixed** +* Python object memory leak was occuring due to incorrect increment of + object reference count in C implementation of object proxy when an + instance method was called via the class and the instance passed in + explicitly. + * In place operators in pure Python object proxy for __idiv__ and __itruediv__ were not replacing the wrapped object with the result of the operation on the wrapped object. diff --git a/src/_wrappers.c b/src/_wrappers.c index 2e61d47..16f8c5b 100644 --- a/src/_wrappers.c +++ b/src/_wrappers.c @@ -1939,13 +1939,11 @@ static PyObject *WraptBoundMethodWrapper_call( object = PyObject_CallFunction(partial, "(OO)", self->object_proxy.wrapped, instance); - if (object) { - Py_INCREF(object); - wrapped = object; - } - else + if (!object) return NULL; + wrapped = object; + param_args = PyTuple_GetSlice(args, 1, PyTuple_Size(args)); if (!param_args) return NULL; @@ -1971,7 +1969,7 @@ static PyObject *WraptBoundMethodWrapper_call( Py_DECREF(call_args); Py_XDECREF(param_args); Py_XDECREF(param_kwds); - Py_XDECREF(wrapped); + Py_DECREF(wrapped); return result; }