Commit cbb866bf authored by Guido van Rossum's avatar Guido van Rossum

Fix a problem with Vladimir's PyFloat_Fini code: clear the free list; if

a block cannot be freed, add its free items back to the free list.
This is necessary to avoid leaking when Python is reinitialized later.
parent 73fdc172
...@@ -631,11 +631,13 @@ PyFloat_Fini() ...@@ -631,11 +631,13 @@ PyFloat_Fini()
fsum = 0; fsum = 0;
list = block_list; list = block_list;
block_list = NULL; block_list = NULL;
free_list = NULL;
while (list != NULL) { while (list != NULL) {
p = &list->objects[0];
bc++; bc++;
frem = 0; frem = 0;
for (i = 0; i < N_FLOATOBJECTS; i++, p++) { for (i = 0, p = &list->objects[0];
i < N_FLOATOBJECTS;
i++, p++) {
if (PyFloat_Check(p) && p->ob_refcnt != 0) if (PyFloat_Check(p) && p->ob_refcnt != 0)
frem++; frem++;
} }
...@@ -643,6 +645,15 @@ PyFloat_Fini() ...@@ -643,6 +645,15 @@ PyFloat_Fini()
if (frem) { if (frem) {
list->next = block_list; list->next = block_list;
block_list = list; block_list = list;
for (i = 0, p = &list->objects[0];
i < N_FLOATOBJECTS;
i++, p++) {
if (!PyFloat_Check(p) || p->ob_refcnt == 0) {
p->ob_type = (struct _typeobject *)
free_list;
free_list = p;
}
}
} }
else { else {
PyMem_FREE(list); PyMem_FREE(list);
...@@ -666,13 +677,14 @@ PyFloat_Fini() ...@@ -666,13 +677,14 @@ PyFloat_Fini()
if (Py_VerboseFlag > 1) { if (Py_VerboseFlag > 1) {
list = block_list; list = block_list;
while (list != NULL) { while (list != NULL) {
p = &list->objects[0]; for (i = 0, p = &list->objects[0];
for (i = 0; i < N_FLOATOBJECTS; i++, p++) { i < N_FLOATOBJECTS;
i++, p++) {
if (PyFloat_Check(p) && p->ob_refcnt != 0) { if (PyFloat_Check(p) && p->ob_refcnt != 0) {
char buf[100]; char buf[100];
PyFloat_AsString(buf, p); PyFloat_AsString(buf, p);
fprintf(stderr, fprintf(stderr,
"# <float object at %lx, refcnt=%d, val=%s>\n", "# <float at %lx, refcnt=%d, val=%s>\n",
p, p->ob_refcnt, buf); p, p->ob_refcnt, buf);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment