From 35efaff73dd81c61de8f1ff006e7a17a25146d14 Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Tue, 24 Feb 2009 21:31:02 -0300 Subject: [PATCH] fix reference leak in the capi export function, add testcase --- Cython/Compiler/ModuleNode.py | 1 + tests/run/capiimpl.pyx | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 tests/run/capiimpl.pyx diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 0e0bdf7e..d24dc489 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -2128,6 +2128,7 @@ static int __Pyx_ExportFunction(const char *name, void *f, const char *sig) { goto bad; if (PyDict_SetItemString(d, name, p) < 0) goto bad; + Py_DECREF(p); Py_DECREF(d); return 0; bad: diff --git a/tests/run/capiimpl.pyx b/tests/run/capiimpl.pyx new file mode 100644 index 00000000..e7ea7e2b --- /dev/null +++ b/tests/run/capiimpl.pyx @@ -0,0 +1,14 @@ +__doc__ = u""" +>>> import sys +>>> sys.getrefcount(Foo.__pyx_vtable__) +2 +>>> sys.getrefcount(__pyx_capi__['spam']) +2 +""" + +cdef public api class Foo [type FooType, object FooObject]: + cdef void bar(self): + pass + +cdef api void spam(): + pass -- 2.26.2