]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Found another memory leak in longrangeiter. And redo the previous correction
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 15 Nov 2007 20:52:21 +0000 (20:52 +0000)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>
Thu, 15 Nov 2007 20:52:21 +0000 (20:52 +0000)
without calling PyType_Ready().

Question 1: Should the interpreter register all types with PyType_Ready()?
Many types seem to avoid it.

Question 2: To reproduce the problem, run the following code:
    def f():
        while True:
           for a in iter(range(0,1,10**20)):
              pass
    f()
And watch the memory used by the process.
How do we test this in a unittest?

Objects/object.c
Objects/rangeobject.c

index fa5eb4d11ba90ac53385d631b600e3bae5854f8f..df93a192d6078ee39e7558a2d2ed38e87d6c72d8 100644 (file)
@@ -1509,9 +1509,6 @@ _Py_ReadyTypes(void)
 
        if (PyType_Ready(&PyStdPrinter_Type) < 0)
                Py_FatalError("Can't initialize StdPrinter");
-
-       if (PyType_Ready(&PyRange_Type) < 0)
-               Py_FatalError("Can't initialize 'range'");
 }
 
 
index e159febdac1f3525743f76375e3bc6157843bcb7..0bb3e7b0ae5f182b0e1d486aabcbb7582d0c6959 100644 (file)
@@ -107,7 +107,7 @@ range_dealloc(rangeobject *r)
     Py_DECREF(r->start);
     Py_DECREF(r->stop);
     Py_DECREF(r->step);
-    Py_Type(r)->tp_free(r);
+    PyObject_Del(r);
 }
 
 /* Return number of items in range (lo, hi, step), when arguments are
@@ -482,6 +482,7 @@ longrangeiter_dealloc(longrangeiterobject *r)
     Py_XDECREF(r->start);
     Py_XDECREF(r->step);
     Py_XDECREF(r->len);
+    PyObject_Del(r);
 }
 
 static PyObject *