]> granicus.if.org Git - python/commitdiff
complex_new(): This could leak when the argument was neither string nor
authorTim Peters <tim.peters@gmail.com>
Fri, 15 Aug 2003 01:16:37 +0000 (01:16 +0000)
committerTim Peters <tim.peters@gmail.com>
Fri, 15 Aug 2003 01:16:37 +0000 (01:16 +0000)
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>).

Misc/NEWS
Objects/complexobject.c

index ee464cac67b9936b5e8f5c1febdd344e73dc00ca..63827d295a817fcccdaff8eb973dc45f822a7433 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.4 alpha 1?
 Core and builtins
 -----------------
 
+- complex(obj) could leak a little memory if obj wasn't a string or
+  number.
+
 - zip() with no arguments now returns an empty list instead of raising
   a TypeError exception.
 
index 4367ff6570eb6e79bac669f42d0cf390bfe019fb..d50a6eb202b2bd3bbb4ec52ed2681494035c4ece 100644 (file)
@@ -882,6 +882,9 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
            ((i != NULL) && (nbi == NULL || nbi->nb_float == NULL))) {
                PyErr_SetString(PyExc_TypeError,
                           "complex() argument must be a string or a number");
+               if (own_r) {
+                       Py_DECREF(r);
+               }
                return NULL;
        }
        if (PyComplex_Check(r)) {