]> granicus.if.org Git - python/commitdiff
Issue #16076: check for return value of PyTuple_New for args (following
authorEli Bendersky <eliben@gmail.com>
Sat, 12 Jan 2013 13:42:38 +0000 (05:42 -0800)
committerEli Bendersky <eliben@gmail.com>
Sat, 12 Jan 2013 13:42:38 +0000 (05:42 -0800)
Coverity report) and cleanup code.

Modules/_elementtree.c

index 8cc98031ca1d15248e8e9837192a9b5120551a7a..3f357b0275f86c063a89c7c028e5590e008d64cf 100644 (file)
@@ -950,19 +950,22 @@ element_setstate_from_Python(ElementObject *self, PyObject *state)
                              PICKLED_TAIL, PICKLED_CHILDREN, 0};
     PyObject *args;
     PyObject *tag, *attrib, *text, *tail, *children;
-    int error;
+    PyObject *retval;
 
-    /* More instance dict members than we know to handle? */
     tag = attrib = text = tail = children = NULL;
     args = PyTuple_New(0);
-    error = ! PyArg_ParseTupleAndKeywords(args, state, "|$OOOOO", kwlist, &tag,
-                                          &attrib, &text, &tail, &children);
-    Py_DECREF(args);
-    if (error)
+    if (!args)
         return NULL;
+
+    if (PyArg_ParseTupleAndKeywords(args, state, "|$OOOOO", kwlist, &tag,
+                                    &attrib, &text, &tail, &children))
+        retval = element_setstate_from_attributes(self, tag, attrib, text,
+                                                  tail, children);
     else
-        return element_setstate_from_attributes(self, tag, attrib, text,
-                                                tail, children);
+        retval = NULL;
+
+    Py_DECREF(args);
+    return retval;
 }
 
 static PyObject *