manodeep / Corrfunc

⚡️⚡️⚡️Blazing fast correlation functions on the CPU.
https://corrfunc.readthedocs.io
MIT License
163 stars 50 forks source link

Fix Python reference leak to results struct #229

Closed lgarrison closed 3 years ago

lgarrison commented 3 years ago

From #227, I think we have a Python reference leak to the results structure. Specifically, I think the following pattern results in a leak:

PyObject *ret = PyList_New(0);//create an empty list
...
return Py_BuildValue("(Od)", ret, c_api_time);

PyBuildValue adds a ref, but the PyList_New reference is never decremented. This PR decrements the ref count after building the tuple, before the return.

Once we verify the fix, I'll port it to the other modules.

lgarrison commented 3 years ago

This is confirmed: sys.getrefcount(extn_results) in DDrppi.py returns 3 instead of 2 without the fix.