]> granicus.if.org Git - python/commitdiff
Deallocate content of the dict free list on interpreter shutdown
authorChristian Heimes <christian@cheimes.de>
Fri, 8 Feb 2008 00:11:31 +0000 (00:11 +0000)
committerChristian Heimes <christian@cheimes.de>
Fri, 8 Feb 2008 00:11:31 +0000 (00:11 +0000)
Include/pythonrun.h
Misc/NEWS
Objects/dictobject.c
Python/pythonrun.c

index cfc40e3a20ef5f812be595523fa78f3cf4218812..0164088b872ecbdc25d3c21feff933bd41db9968 100644 (file)
@@ -130,6 +130,7 @@ PyAPI_FUNC(void) _PyImport_Fini(void);
 PyAPI_FUNC(void) PyMethod_Fini(void);
 PyAPI_FUNC(void) PyFrame_Fini(void);
 PyAPI_FUNC(void) PyCFunction_Fini(void);
+PyAPI_FUNC(void) PyDict_Fini(void);
 PyAPI_FUNC(void) PyTuple_Fini(void);
 PyAPI_FUNC(void) PyList_Fini(void);
 PyAPI_FUNC(void) PySet_Fini(void);
index d15531dc1390f160c90ace56db16474d2f93324f..af9f36452c7cc804db09ec1933892f336c6ac8d1 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 2.6 alpha 1?
 Core and builtins
 -----------------
 
+- Fixed a minor memory leak in dictobject.c. The content of the free
+  list was not freed on interpreter shutdown.
+
 - Limit free list of method and builtin function objects to 256 entries
   each.
 
index 82d247f3f9515309962e5355536f4784bff94192..9e2b9445794d041021b6ef57aeebe31dffbedcdc 100644 (file)
@@ -205,6 +205,18 @@ show_alloc(void)
 static PyDictObject *free_list[PyDict_MAXFREELIST];
 static int numfree = 0;
 
+void
+PyDict_Fini(void)
+{
+       PyListObject *op;
+
+       while (numfree) {
+               op = free_list[numfree--];
+               assert(PyDict_CheckExact(op));
+               PyObject_GC_Del(op);
+       }
+}
+
 PyObject *
 PyDict_New(void)
 {
index f5465c5edeea64076e2bd1a727666c48d38e7323..ec31af10c9e02f39e3df2e65bb9220bca424986b 100644 (file)
@@ -473,6 +473,7 @@ Py_Finalize(void)
        PyString_Fini();
        PyInt_Fini();
        PyFloat_Fini();
+       PyDict_Fini();
 
 #ifdef Py_USING_UNICODE
        /* Cleanup Unicode implementation */