]> granicus.if.org Git - python/commitdiff
Refcounting fixes
authorNick Coghlan <ncoghlan@gmail.com>
Sun, 15 Jul 2012 13:21:08 +0000 (23:21 +1000)
committerNick Coghlan <ncoghlan@gmail.com>
Sun, 15 Jul 2012 13:21:08 +0000 (23:21 +1000)
Python/pythonrun.c

index 33ac741de01fd3dcc47e74a29392a2b4e8da82dc..6ee9a5fddfc04659982112967e5bbec51a84b944 100644 (file)
@@ -1356,6 +1356,7 @@ static set_main_loader(PyObject *d, const char *filename, const char *loader_nam
     PyInterpreterState *interp;
     PyThreadState *tstate;
     PyObject *loader_type, *loader;
+    int result = 0;
     /* Get current thread state and interpreter pointer */
     tstate = PyThreadState_GET();
     interp = tstate->interp;
@@ -1364,12 +1365,15 @@ static set_main_loader(PyObject *d, const char *filename, const char *loader_nam
         return -1;
     }
     loader = PyObject_CallFunction(loader_type, "ss", "__main__", filename);
-    if (loader == NULL ||
-        (PyDict_SetItemString(d, "__loader__", loader) < 0)) {
+    Py_DECREF(loader_type);
+    if (loader == NULL) {
         return -1;
     }
+    if (PyDict_SetItemString(d, "__loader__", loader) < 0) {
+        result = -1;
+    }
     Py_DECREF(loader);
-    return 0;
+    return result;
 }
 
 int