I call a Python method from C and it leak / seg fault on PyObject_CallMethod after 10 hours.
Can you review my code? Where is my error? Missing somethings?
The C code:
PyObject *pFrameAsList = PyList_New(0);
...
for (int k=0; k<m_nbImages; ++k)
{
PyObject *pFrameAsArray = toNDArray(frame);
...
PyList_Append(pFrameAsList, pFrameAsArray);
Py_DECREF(pFrameAsArray);
}
PyObject *pValue = PyObject_CallMethod(pInstance, "analyseFrame", "(O)", pFrameAsList);
...
Py_INCREF(pValue);
...
for (int k=0 ; k<max; k++ )
{
PyObject *ptemp = PyList_GetItem(pValue,k);
}
Py_DECREF(pFrameAsList);
Py_DECREF(pValue);
And the Python code:
def analyseFrame(self, frame):
results = self.model.analyse(np.asarray(frame))
return list(results)