Commits

Anonymous committed 5e0085d Merge

Issue #13020: Fix a reference leak when allocating a structsequence object fails.
Patch by Suman Saha.

Comments (0)

Files changed (2)

 Core and Builtins
 -----------------
 
+- Issue #13020: Fix a reference leak when allocating a structsequence object
+  fails.  Patch by Suman Saha.
+
 - Issue #13777: Add PF_SYSTEM sockets on OS X.
   Patch by Michael Goderbauer.
 

Objects/structseq.c

     if (min_len != max_len) {
         if (len < min_len) {
             PyErr_Format(PyExc_TypeError,
-           "%.500s() takes an at least %zd-sequence (%zd-sequence given)",
-                                 type->tp_name, min_len, len);
-                    Py_DECREF(arg);
-                    return NULL;
+                "%.500s() takes an at least %zd-sequence (%zd-sequence given)",
+                type->tp_name, min_len, len);
+            Py_DECREF(arg);
+            return NULL;
         }
 
         if (len > max_len) {
             PyErr_Format(PyExc_TypeError,
-           "%.500s() takes an at most %zd-sequence (%zd-sequence given)",
-                                 type->tp_name, max_len, len);
-                    Py_DECREF(arg);
-                    return NULL;
+                "%.500s() takes an at most %zd-sequence (%zd-sequence given)",
+                type->tp_name, max_len, len);
+            Py_DECREF(arg);
+            return NULL;
         }
     }
     else {
         if (len != min_len) {
             PyErr_Format(PyExc_TypeError,
-           "%.500s() takes a %zd-sequence (%zd-sequence given)",
-                                 type->tp_name, min_len, len);
-                    Py_DECREF(arg);
-                    return NULL;
+                         "%.500s() takes a %zd-sequence (%zd-sequence given)",
+                         type->tp_name, min_len, len);
+            Py_DECREF(arg);
+            return NULL;
         }
     }
 
     res = (PyStructSequence*) PyStructSequence_New(type);
     if (res == NULL) {
+        Py_DECREF(arg);
         return NULL;
     }
     for (i = 0; i < len; ++i) {