summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1999-03-19 20:59:40 (GMT)
committerGuido van Rossum <guido@python.org>1999-03-19 20:59:40 (GMT)
commitd7b5fb858cce7ae7a1edd379a6ddf5d3ed3a8baf (patch)
tree220761c0dc6f78bc2ae4351f1b4d86a67da528a1 /Objects
parent51288bce482d076917c5ce5a3a5b48e7aa6031cb (diff)
downloadcpython-d7b5fb858cce7ae7a1edd379a6ddf5d3ed3a8baf.zip
cpython-d7b5fb858cce7ae7a1edd379a6ddf5d3ed3a8baf.tar.gz
cpython-d7b5fb858cce7ae7a1edd379a6ddf5d3ed3a8baf.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 34fd317..120b561 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -631,11 +631,13 @@ PyFloat_Fini()
fsum = 0;
list = block_list;
block_list = NULL;
+ free_list = NULL;
while (list != NULL) {
- p = &list->objects[0];
bc++;
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)
frem++;
}
@@ -643,6 +645,15 @@ PyFloat_Fini()
if (frem) {
list->next = block_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 {
PyMem_FREE(list);
@@ -666,13 +677,14 @@ PyFloat_Fini()
if (Py_VerboseFlag > 1) {
list = block_list;
while (list != NULL) {
- p = &list->objects[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) {
char buf[100];
PyFloat_AsString(buf, p);
fprintf(stderr,
- "# <float object at %lx, refcnt=%d, val=%s>\n",
+ "# <float at %lx, refcnt=%d, val=%s>\n",
p, p->ob_refcnt, buf);
}
}