BUG: iterator_to_pylist_deref and iterator_to_pylist leak 1 reference
opened this issue · comments
llvmpy/include/llvm_binding/extra.h
- pycapsule_new calls PyCapsule_New which returns a NEW reference
- PyList_Append calls Py_INCREF implicitly
- Original reference must have Py_DECREF called
diff:
--- e:\llvmpy-llvmpy-0.12.1-1-gc199881_foo\llvmpy-llvmpy-c199881\llvmpy\include\llvm_binding\extra.h Mon Nov 18 16:59:01 2013
+++ llvmpy\include\llvm_binding\extra.h Wed Jan 08 16:14:10 2014
@@ -184,26 +184,28 @@
PyObject* iterator_to_pylist_deref(iterator begin, iterator end,
const char *capsuleName, const char *className)
{
PyObject* list = PyList_New(0);
for(; begin != end; ++begin) {
PyObject* cap = pycapsule_new(&*begin, capsuleName, className);
PyList_Append(list, cap);
+ Py_DECREF(cap);
}
return list;
}
template<class iterator>
PyObject* iterator_to_pylist(iterator begin, iterator end,
const char *capsuleName, const char *className)
{
PyObject* list = PyList_New(0);
for(; begin != end; ++begin) {
PyObject* cap = pycapsule_new(*begin, capsuleName, className);
PyList_Append(list, cap);
+ Py_DECREF(cap);
}
return list;
}
template<class iplist>
PyObject* iplist_to_pylist(iplist &IPL, const char * capsuleName,
const char* className){
I've found the same problem. There are a couple more similar leaks, here's my patch: https://gist.github.com/eltjpm/8834958
I should have done this earlier.