]> granicus.if.org Git - python/commitdiff
initerrors(): Eliminate circular reference which was causing a small
authorBarry Warsaw <barry@python.org>
Thu, 18 Sep 1997 03:44:38 +0000 (03:44 +0000)
committerBarry Warsaw <barry@python.org>
Thu, 18 Sep 1997 03:44:38 +0000 (03:44 +0000)
but annoying memory leak.  This was introduced when PyExc_Exception
was added; the loop above populating the PyExc_StandardError exception
tuple started at index 1 in bltin_exc, but PyExc_Exception was added
at index 0, so PyExc_StandardError was getting inserted in itself!
How else can a tuple include itself?!

Change the loop to start at index 2.

This was a *fun* one! :-)

Python/bltinmodule.c

index 65cfa6f63ab315ce4be4682872e078af3925bd60..15cca17913e1fa0f8e5931b55c5d0186ecfcb0e2 100644 (file)
@@ -1896,11 +1896,11 @@ initerrors(dict)
        PyTuple_SET_ITEM(PyExc_ArithmeticError, 2, PyExc_FloatingPointError);
        PyDict_SetItemString(dict, "ArithmeticError", PyExc_ArithmeticError);
 
-       PyExc_StandardError = PyTuple_New(exccnt-1);
-       for (i = 1; bltin_exc[i].name; i++) {
+       PyExc_StandardError = PyTuple_New(exccnt-2);
+       for (i = 2; bltin_exc[i].name; i++) {
                PyObject *exc = *bltin_exc[i].exc;
                Py_INCREF(exc);
-               PyTuple_SET_ITEM(PyExc_StandardError, i-1, exc);
+               PyTuple_SET_ITEM(PyExc_StandardError, i-2, exc);
        }
        PyDict_SetItemString(dict, "StandardError", PyExc_StandardError);