diff Python/ceval.c @ 76419:293180d199f2

Fix refleak: PyObject_GetItem returns a new reference, not a borrowed one like PyDict_GetItem.
author Antoine Pitrou <solipsis@pitrou.net>
date Thu, 19 Apr 2012 18:21:04 +0200
parents e3ab8aa0216c
children 6e5855854a2e
line wrap: on
line diff
--- a/Python/ceval.c	Thu Apr 19 14:33:43 2012 +0200
+++ b/Python/ceval.c	Thu Apr 19 18:21:04 2012 +0200
@@ -1940,6 +1940,7 @@
                                     "__build_class__ not found");
                     break;
                 }
+                Py_INCREF(x);
             }
             else {
                 PyObject *build_class_str = _PyUnicode_FromId(&PyId___build_class__);
@@ -1953,7 +1954,6 @@
                     break;
                 }
             }
-            Py_INCREF(x);
             PUSH(x);
             break;
         }
@@ -2092,6 +2092,7 @@
             }
             if (x == NULL) {
                 x = PyDict_GetItem(f->f_globals, w);
+                Py_XINCREF(x);
                 if (x == NULL) {
                     if (PyDict_CheckExact(f->f_builtins)) {
                         x = PyDict_GetItem(f->f_builtins, w);
@@ -2101,6 +2102,7 @@
                                         NAME_ERROR_MSG, w);
                             break;
                         }
+                        Py_INCREF(x);
                     }
                     else {
                         x = PyObject_GetItem(f->f_builtins, w);
@@ -2113,7 +2115,6 @@
                         }
                     }
                 }
-                Py_INCREF(x);
             }
             PUSH(x);
             DISPATCH();
@@ -2186,7 +2187,6 @@
                     break;
                 }
             }
-            Py_INCREF(x);
             PUSH(x);
             DISPATCH();