Skip to content

Commit

Permalink
Merge pull request numpy#16336 from seberg/trivial-refcountfix-add_do…
Browse files Browse the repository at this point in the history
…cstring

BUG: Fix refcounting in add_newdoc
  • Loading branch information
charris authored May 22, 2020
2 parents 16692b1 + 8029c45 commit fc2518b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion numpy/core/src/multiarray/compiled_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args)
#define _ADDDOC(doc, name) \
if (!(doc)) { \
doc = docstr; \
Py_INCREF(str); /* hold on to string (leaks reference) */ \
} \
else if (strcmp(doc, docstr) != 0) { \
PyErr_Format(PyExc_RuntimeError, "%s method %s", name, msg); \
Expand Down Expand Up @@ -1476,6 +1477,7 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args)
doc_attr = PyObject_GetAttrString(obj, "__doc__");
if (doc_attr != NULL && doc_attr != Py_None &&
(PyUnicode_Compare(doc_attr, str) != 0)) {
Py_DECREF(doc_attr);
if (PyErr_Occurred()) {
/* error during PyUnicode_Compare */
return NULL;
Expand All @@ -1495,7 +1497,6 @@ arr_add_docstring(PyObject *NPY_UNUSED(dummy), PyObject *args)

#undef _ADDDOC

Py_INCREF(str);
Py_RETURN_NONE;
}

Expand Down

0 comments on commit fc2518b

Please sign in to comment.