Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b78174c

Browse files
committed
Fix too early decrefs.
1 parent 9d9dc8e commit b78174c

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Python/import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,14 +1639,14 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
16391639

16401640
if (level == 0) {
16411641
final_mod = PyDict_GetItem(interp->modules, front);
1642-
Py_DECREF(front);
16431642
if (final_mod == NULL) {
16441643
PyErr_Format(PyExc_KeyError,
16451644
"%R not in sys.modules as expected", front);
16461645
}
16471646
else {
16481647
Py_INCREF(final_mod);
16491648
}
1649+
Py_DECREF(front);
16501650
}
16511651
else {
16521652
Py_ssize_t cut_off = PyUnicode_GET_LENGTH(name) -
@@ -1660,7 +1660,6 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
16601660
}
16611661

16621662
final_mod = PyDict_GetItem(interp->modules, to_return);
1663-
Py_DECREF(to_return);
16641663
if (final_mod == NULL) {
16651664
PyErr_Format(PyExc_KeyError,
16661665
"%R not in sys.modules as expected",
@@ -1669,6 +1668,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
16691668
else {
16701669
Py_INCREF(final_mod);
16711670
}
1671+
Py_DECREF(to_return);
16721672
}
16731673
}
16741674
else {

0 commit comments

Comments
 (0)