From 37784ba5c08aed9a3153eb5a37014e59ee3769fe Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 15 Feb 2012 02:51:43 +0100 Subject: [PATCH 1/2] Issue #13020: Fix a reference leak when allocating a structsequence object fails. Patch by Suman Saha. --- Misc/NEWS | 3 +++ Objects/structseq.c | 1 + 2 files changed, 4 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index 0ef337c56bd..4d3d665e54d 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.2.3? Core and Builtins ----------------- +- Issue #13020: Fix a reference leak when allocating a structsequence object + fails. Patch by Suman Saha. + - Issue #13908: Ready types returned from PyType_FromSpec. - Issue #11235: Fix OverflowError when trying to import a source file whose diff --git a/Objects/structseq.c b/Objects/structseq.c index ef17f49a314..ac4f980a069 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -129,6 +129,7 @@ structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwds) res = (PyStructSequence*) PyStructSequence_New(type); if (res == NULL) { + Py_DECREF(arg); return NULL; } for (i = 0; i < len; ++i) { From 4b3c7846c9a25dfe4e508d9059ff8274023acd09 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Wed, 15 Feb 2012 02:52:58 +0100 Subject: [PATCH 2/2] Fix indentation --- Objects/structseq.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Objects/structseq.c b/Objects/structseq.c index ac4f980a069..28cbb1901f4 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -103,27 +103,27 @@ structseq_new(PyTypeObject *type, PyObject *args, PyObject *kwds) 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; } }