]> granicus.if.org Git - python/commitdiff
Fix memory leak on attributes.
authorMartin v. Löwis <martin@v.loewis.de>
Thu, 2 Mar 2006 00:31:27 +0000 (00:31 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Thu, 2 Mar 2006 00:31:27 +0000 (00:31 +0000)
Parser/asdl_c.py
Python/Python-ast.c

index 3e2acf4372c5cb1f830e7dfe288b6e004bfab144..ad2209d0038b7b1f2fa97c6c4efbb7ab19cec744 100755 (executable)
@@ -607,7 +607,9 @@ class ObjVisitor(PickleVisitor):
         for a in sum.attributes:
             self.emit("value = ast2obj_%s(o->%s);" % (a.type, a.name), 1)
             self.emit("if (!value) goto failed;", 1)
-            self.emit('PyObject_SetAttrString(result, "%s", value);' % a.name, 1)
+            self.emit('if (PyObject_SetAttrString(result, "%s", value) < 0)' % a.name, 1)
+            self.emit('goto failed;', 2)
+            self.emit('Py_DECREF(value);', 1)
         self.func_end()
 
     def simpleSum(self, sum, name):
index 3e49212a048b7d94398aa3c2641876bc2fcd4af2..3f8345ebf483107499593052c841e5afd813c61a 100644 (file)
@@ -2324,10 +2324,14 @@ ast2obj_stmt(void* _o)
         }
         value = ast2obj_int(o->lineno);
         if (!value) goto failed;
-        PyObject_SetAttrString(result, "lineno", value);
+        if (PyObject_SetAttrString(result, "lineno", value) < 0)
+                goto failed;
+        Py_DECREF(value);
         value = ast2obj_int(o->col_offset);
         if (!value) goto failed;
-        PyObject_SetAttrString(result, "col_offset", value);
+        if (PyObject_SetAttrString(result, "col_offset", value) < 0)
+                goto failed;
+        Py_DECREF(value);
         return result;
 failed:
         Py_XDECREF(value);
@@ -2643,10 +2647,14 @@ ast2obj_expr(void* _o)
         }
         value = ast2obj_int(o->lineno);
         if (!value) goto failed;
-        PyObject_SetAttrString(result, "lineno", value);
+        if (PyObject_SetAttrString(result, "lineno", value) < 0)
+                goto failed;
+        Py_DECREF(value);
         value = ast2obj_int(o->col_offset);
         if (!value) goto failed;
-        PyObject_SetAttrString(result, "col_offset", value);
+        if (PyObject_SetAttrString(result, "col_offset", value) < 0)
+                goto failed;
+        Py_DECREF(value);
         return result;
 failed:
         Py_XDECREF(value);
@@ -3023,7 +3031,7 @@ init_ast(void)
         if (PyDict_SetItemString(d, "AST", (PyObject*)AST_type) < 0) return;
         if (PyModule_AddIntConstant(m, "PyCF_ONLY_AST", PyCF_ONLY_AST) < 0)
                 return;
-        if (PyModule_AddStringConstant(m, "__version__", "42649") < 0)
+        if (PyModule_AddStringConstant(m, "__version__", "42753") < 0)
                 return;
         if(PyDict_SetItemString(d, "mod", (PyObject*)mod_type) < 0) return;
         if(PyDict_SetItemString(d, "Module", (PyObject*)Module_type) < 0)