From: Barry Warsaw Date: Thu, 18 Sep 1997 03:44:38 +0000 (+0000) Subject: initerrors(): Eliminate circular reference which was causing a small X-Git-Tag: v1.5a4~145 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b01a7fa5f8208fb5c767964e63b44f0a02814f62;p=python initerrors(): Eliminate circular reference which was causing a small 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! :-) --- diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 65cfa6f63a..15cca17913 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -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);