Category : python-extensions

There is a memory leak in my encode method. static const size_t _bits_per_digit = sizeof(digit) * CHAR_BIT; /** * Returns a Python int storing the bitstream of the Elias gamma encoded input list. */ static PyObject * encode(PyObject *self, PyObject *obj) { if (!PyList_Check(obj)) { PyErr_SetString(PyExc_TypeError, "Input to encode must be a list"); return NULL; ..

Read more

https://github.com/python/cpython/blob/master/Include/objimpl.h#L83 says PyObject_Realloc(p != NULL, 0) does not return NULL, or free the memory at p. PyObject_Realloc doesn’t free the memory. I’ve noticed a memory leak in my program which uses PyObject_Realloc every now and then. I tried to fix it using this: PyLongObject *new = (PyLongObject *) PyObject_Realloc(obj, new_size); if (new == NULL) { ..

Read more