diff Python/import.c @ 76799:49306ceaf91f

Fix too early decrefs.
author Antoine Pitrou <solipsis@pitrou.net>
date Sun, 06 May 2012 17:15:23 +0200
parents babe4dd3fe0d
children d6324941b739
line wrap: on
line diff
--- a/Python/import.c	Sun May 06 16:25:35 2012 +0200
+++ b/Python/import.c	Sun May 06 17:15:23 2012 +0200
@@ -1639,7 +1639,6 @@
 
             if (level == 0) {
                 final_mod = PyDict_GetItem(interp->modules, front);
-                Py_DECREF(front);
                 if (final_mod == NULL) {
                     PyErr_Format(PyExc_KeyError,
                                  "%R not in sys.modules as expected", front);
@@ -1647,6 +1646,7 @@
                 else {
                     Py_INCREF(final_mod);
                 }
+                Py_DECREF(front);
             }
             else {
                 Py_ssize_t cut_off = PyUnicode_GET_LENGTH(name) -
@@ -1660,7 +1660,6 @@
                 }
 
                 final_mod = PyDict_GetItem(interp->modules, to_return);
-                Py_DECREF(to_return);
                 if (final_mod == NULL) {
                     PyErr_Format(PyExc_KeyError,
                                  "%R not in sys.modules as expected",
@@ -1669,6 +1668,7 @@
                 else {
                     Py_INCREF(final_mod);
                 }
+                Py_DECREF(to_return);
             }
         }
         else {