diff options
author | Guido van Rossum <guido@python.org> | 1999-03-19 20:30:39 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1999-03-19 20:30:39 (GMT) |
commit | 51288bce482d076917c5ce5a3a5b48e7aa6031cb (patch) | |
tree | dfcb5869745b8687bd296069b17e9a69314e1e1e /Objects | |
parent | 8be229650dd59c06c369e3ccb5394f9243f78501 (diff) | |
download | cpython-51288bce482d076917c5ce5a3a5b48e7aa6031cb.zip cpython-51288bce482d076917c5ce5a3a5b48e7aa6031cb.tar.gz cpython-51288bce482d076917c5ce5a3a5b48e7aa6031cb.tar.bz2 |
Fix a problem with Vladimir's PyInt_Fini code: clear the free list; if
a block cannot be freed, add its free items back to the free list, and
add its valid ints back to the small_ints array if they are in range.
This is necessary to avoid leaking when Python is reinitialized later.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/intobject.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index 0bf1fc5..7293515 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -831,11 +831,13 @@ PyInt_Fini() isum = 0; list = block_list; block_list = NULL; + free_list = NULL; while (list != NULL) { - p = &list->objects[0]; bc++; irem = 0; - for (i = 0; i < N_INTOBJECTS; i++, p++) { + for (i = 0, p = &list->objects[0]; + i < N_INTOBJECTS; + i++, p++) { if (PyInt_Check(p) && p->ob_refcnt != 0) irem++; } @@ -843,6 +845,25 @@ PyInt_Fini() if (irem) { list->next = block_list; block_list = list; + for (i = 0, p = &list->objects[0]; + i < N_INTOBJECTS; + i++, p++) { + if (!PyInt_Check(p) || p->ob_refcnt == 0) { + p->ob_type = (struct _typeobject *) + free_list; + free_list = p; + } +#if NSMALLNEGINTS + NSMALLPOSINTS > 0 + else if (-NSMALLNEGINTS <= p->ob_ival && + p->ob_ival < NSMALLPOSINTS && + small_ints[p->ob_ival + + NSMALLNEGINTS] == NULL) { + Py_INCREF(p); + small_ints[p->ob_ival + + NSMALLNEGINTS] = p; + } +#endif + } } else { PyMem_FREE(list); @@ -866,11 +887,12 @@ PyInt_Fini() if (Py_VerboseFlag > 1) { list = block_list; while (list != NULL) { - p = &list->objects[0]; - for (i = 0; i < N_INTOBJECTS; i++, p++) { + for (i = 0, p = &list->objects[0]; + i < N_INTOBJECTS; + i++, p++) { if (PyInt_Check(p) && p->ob_refcnt != 0) fprintf(stderr, - "# <int object at %lx, refcnt=%d, val=%ld>\n", + "# <int at %lx, refcnt=%d, val=%ld>\n", p, p->ob_refcnt, p->ob_ival); } list = list->next; |