summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-02-15 02:54:33 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2012-02-15 02:54:33 +0100
commit552be9b21441514f98356135da7b226914115acf (patch)
treeb87ed275d03e36940dd51f19f28f79a8de311b74
parent15af7b4a4f38be7155c4186624d67dc12764aceb (diff)
parent4b3c7846c9a25dfe4e508d9059ff8274023acd09 (diff)
downloadcpython-git-552be9b21441514f98356135da7b226914115acf.tar.gz
Issue #13020: Fix a reference leak when allocating a structsequence object fails.
Patch by Suman Saha.
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/structseq.c25
2 files changed, 16 insertions, 12 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index 2f8a5c198b..b57cd2146a 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1?
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.
diff --git a/Objects/structseq.c b/Objects/structseq.c
index ef17f49a31..28cbb1901f 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -103,32 +103,33 @@ 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;
}
}
res = (PyStructSequence*) PyStructSequence_New(type);
if (res == NULL) {
+ Py_DECREF(arg);
return NULL;
}
for (i = 0; i < len; ++i) {