Skip to content

Commit 1988e07

Browse files
author
tim_one
committed
complex_new(): This could leak when the argument was neither string nor
number. This accounts for the 2 refcount leaks per test_complex run Michael Hudson discovered (I figured only I would have the stomach to look for leaks in floating-point code <wink>). git-svn-id: http://svn.python.org/projects/python/trunk@33863 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 4702baf commit 1988e07

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.4 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- complex(obj) could leak a little memory if obj wasn't a string or
16+
number.
17+
1518
- zip() with no arguments now returns an empty list instead of raising
1619
a TypeError exception.
1720

Objects/complexobject.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,9 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
882882
((i != NULL) && (nbi == NULL || nbi->nb_float == NULL))) {
883883
PyErr_SetString(PyExc_TypeError,
884884
"complex() argument must be a string or a number");
885+
if (own_r) {
886+
Py_DECREF(r);
887+
}
885888
return NULL;
886889
}
887890
if (PyComplex_Check(r)) {

0 commit comments

Comments
 (0)