Skip to content

Commit

Permalink
Fix leak in nrncore_arg.
Browse files Browse the repository at this point in the history
Because `PyObject_GetAttrString` returns a new reference [1], we're
responsible for calling DECREF on the `callable`.

[1]: https://docs.python.org/3/c-api/object.html#c.PyObject_GetAttrString
  • Loading branch information
1uc committed Nov 15, 2024
1 parent cdd3fae commit 86360ce
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/nrnpython/nrnpy_hoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3335,11 +3335,11 @@ static char* nrncore_arg(double tstop) {
if (modules) {
PyObject* module = PyDict_GetItemString(modules, "neuron.coreneuron");
if (module) {
PyObject* callable = PyObject_GetAttrString(module, "nrncore_arg");
auto callable = nb::steal(PyObject_GetAttrString(module, "nrncore_arg"));
if (callable) {
PyObject* ts = Py_BuildValue("(d)", tstop);
if (ts) {
PyObject* arg = PyObject_CallObject(callable, ts);
PyObject* arg = PyObject_CallObject(callable.ptr(), ts);
Py_DECREF(ts);
if (arg) {
Py2NRNString str(arg);
Expand Down

0 comments on commit 86360ce

Please sign in to comment.