Skip to content

Commit 6ec81c7

Browse files
committed
Update reference counting
from Barry Warsaw: - It's possible the code jumps to error: after pkgname is decref'd. I think that decref should be deferred until just before the good-path return. - pkgname_or_unknown will be a new reference if pkgname is NULL, or it will steal the pkgname reference if it's not. In either case, the error stanza should decref pkgname_or_unknown, which will take care of ensuring the object gets decref for any goto error path. - pkgpath doesn't get decref'd. I think you should Py_XDECREF it before the return NULL just in case pkgpath is itself NULL.
1 parent a181463 commit 6ec81c7

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Python/ceval.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5009,7 +5009,6 @@ import_from(PyObject *v, PyObject *name)
50095009
goto error;
50105010
}
50115011
fullmodname = PyUnicode_FromFormat("%U.%U", pkgname, name);
5012-
Py_DECREF(pkgname);
50135012
if (fullmodname == NULL) {
50145013
return NULL;
50155014
}
@@ -5018,6 +5017,7 @@ import_from(PyObject *v, PyObject *name)
50185017
if (x == NULL) {
50195018
goto error;
50205019
}
5020+
Py_DECREF(pkgname);
50215021
Py_INCREF(x);
50225022
return x;
50235023
error:
@@ -5041,6 +5041,8 @@ import_from(PyObject *v, PyObject *name)
50415041
pkgname, pkgpath);
50425042
}
50435043

5044+
Py_XDECREF(pkgname_or_unknown);
5045+
Py_XDECREF(pkgpath);
50445046
return NULL;
50455047
}
50465048

0 commit comments

Comments
 (0)