[Python-bugs-list] _PyBuiltin_Init memory leak (PR#363)
cfandrich@8cs.com
cfandrich@8cs.com
Mon, 19 Jun 2000 20:14:38 -0400 (EDT)
Full_Name: Christopher Fandrich
Version: 1.5.2
OS: Windows
Submission from: (NULL) (208.41.174.4)
I think there's a memory leak in _PyBuiltin_Init on the following line:
if (PyDict_SetItemString(dict, "__debug__",
PyInt_FromLong(Py_OptimizeFlag == 0)) < 0)
If I understand this correctly, PyInt_FromLong incref's its return value once,
and PyDict_SetItemString incref's it a second time. I think this is preventing
the "__debug__" value from being deleted. If this is so, the following patch
should fix it.
Index: ./1.5.2a/Python/bltinmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/bltinmodule.c,v
retrieving revision 2.161
diff -c -r2.161 bltinmodule.c
*** ./1.5.2a/Python/bltinmodule.c 2000/05/25 23:15:05 2.161
--- ./1.5.2a/Python/bltinmodule.c 2000/06/20 00:03:20
***************
*** 2364,2370 ****
PyObject *
_PyBuiltin_Init()
{
! PyObject *mod, *dict;
mod = Py_InitModule4("__builtin__", builtin_methods,
builtin_doc, (PyObject *)NULL,
PYTHON_API_VERSION);
--- 2364,2370 ----
PyObject *
_PyBuiltin_Init()
{
! PyObject *mod, *dict, *debug;
mod = Py_InitModule4("__builtin__", builtin_methods,
builtin_doc, (PyObject *)NULL,
PYTHON_API_VERSION);
***************
*** 2375,2383 ****
return NULL;
if (PyDict_SetItemString(dict, "Ellipsis", Py_Ellipsis) < 0)
return NULL;
! if (PyDict_SetItemString(dict, "__debug__",
! PyInt_FromLong(Py_OptimizeFlag == 0)) < 0)
return NULL;
return mod;
}
--- 2375,2387 ----
return NULL;
if (PyDict_SetItemString(dict, "Ellipsis", Py_Ellipsis) < 0)
return NULL;
! debug = PyInt_FromLong(Py_OptimizeFlag == 0);
! if (PyDict_SetItemString(dict, "__debug__",debug) < 0)
! {
! Py_XDECREF(debug);
return NULL;
+ }
+ Py_XDECREF(debug);
return mod;
}
-----------------------------------------------------------------
I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims"). To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.
I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation. I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.
-chris