Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix reference counting leak in
nrnpy_restore_savestate_
.
The facts: 1. `PyByteArray_FromStringAndSize` returns a "new reference" [1]. 2. `PyObject_CallObject` returns a "new reference" [2]. 3. `PyTuple_SetItem` steals `py_data` [3]. Let's analyse `py_data` first: * After `PyByteArray_FromStringAndSize` it's at `+1` (meaning 1 unaccounted INCREF). * After `Py_INCREF(py_data)` it's at `+2`. * By calling `PyTuple_SetItem` we know 1 DECREF will happen, because it steals `py_data`. The reference count of `py_data` is at `+1`. Therefore, there's one INCREF for which we can't pair up with a DECREF. Let's move on to `result`, since it's a "new reference" we're responsible for calling `DECREF`. [1]: https://docs.python.org/3/c-api/bytearray.html#c.PyByteArray_FromStringAndSize [2]: https://docs.python.org/3/c-api/call.html#c.PyObject_CallObject [3]: https://docs.python.org/3/c-api/tuple.html#c.PyTuple_SetItem
- Loading branch information