Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix Proxy implemented in cext.c memory leak
remove Py_INCREF(wrapped) cause PyObject_CallFunctionObjArgs had created
a new reference to wrapped

also remove some useless code and make some more pythonic
  • Loading branch information
郭旭星 Astrum Kuo committed Aug 18, 2015
commit 554cce876b28dd834523b13080cad523db323181
10 changes: 2 additions & 8 deletions src/lazy_object_proxy/cext.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ static PyObject *Proxy__ensure_wrapped(ProxyObject *self)
if (self->factory) {
wrapped = PyObject_CallFunctionObjArgs(self->factory, NULL);
if (wrapped) {
Py_INCREF(wrapped);
self->wrapped = wrapped;
return wrapped;
} else {
Expand All @@ -75,8 +74,6 @@ static PyObject *Proxy__ensure_wrapped(ProxyObject *self)
PyErr_SetString(PyExc_ValueError, "Proxy hasn't been initiated: __factory__ is missing.");
return NULL;
}


}
}

Expand Down Expand Up @@ -1071,7 +1068,7 @@ static int Proxy_set_wrapped(ProxyObject *self,
PyObject *value)
{
if (value) Py_INCREF(value);
if (self->wrapped) Py_DECREF(self->wrapped);
Py_XDECREF(self->wrapped);

self->wrapped = value;

Expand All @@ -1093,7 +1090,7 @@ static int Proxy_set_factory(ProxyObject *self,
PyObject *value)
{
if (value) Py_INCREF(value);
Py_DECREF(self->factory);
Py_XDECREF(self->factory);

self->factory = value;

Expand Down Expand Up @@ -1395,9 +1392,6 @@ moduleinit(void)
if (PyType_Ready(&Proxy_Type) < 0)
return NULL;

if (PyType_Ready(&Proxy_Type) < 0)
return NULL;

dict = PyModule_GetDict(module);
if (dict == NULL)
return NULL;
Expand Down