[Python-checkins] CVS: python/dist/src/Python compile.c,2.168,2.169 symtable.c,2.1,2.2
Jeremy Hylton
jhylton@users.sourceforge.net
Fri, 23 Feb 2001 09:55:30 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv32394
Modified Files:
compile.c symtable.c
Log Message:
Fix for bug 133489: compiler leaks memory
Two different but related problems:
1. PySymtable_Free() must explicitly DECREF(st->st_cur), which should
always point to the global symtable entry. This entry is setup by the
first enter_scope() call, but there is never a corresponding
exit_scope() call.
Since each entry has a reference to scopes defined within it, the
missing DECREF caused all symtable entries to be leaked.
2. The leak here masked a separate problem with
PySymtableEntry_New(). When the requested entry was found in
st->st_symbols, the entry was returned without doing an INCREF.
And problem c) The ste_children slot was getting two copies of each
child entry, because it was populating the slot on the first and
second passes. Now only populate on the first pass.
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.168
retrieving revision 2.169
diff -C2 -r2.168 -r2.169
*** compile.c 2001/02/19 23:52:49 2.168
--- compile.c 2001/02/23 17:55:27 2.169
***************
*** 3913,3918 ****
}
exit:
! if (base == NULL)
PySymtable_Free(sc.c_symtable);
com_free(&sc);
return co;
--- 3913,3920 ----
}
exit:
! if (base == NULL) {
PySymtable_Free(sc.c_symtable);
+ sc.c_symtable = NULL;
+ }
com_free(&sc);
return co;
***************
*** 4194,4197 ****
--- 4196,4200 ----
Py_XDECREF(st->st_symbols);
Py_XDECREF(st->st_stack);
+ Py_XDECREF(st->st_cur);
PyMem_Free((void *)st);
}
***************
*** 4360,4367 ****
if (strcmp(name, TOP) == 0)
st->st_global = st->st_cur->ste_symbols;
! if (prev)
if (PyList_Append(prev->ste_children,
(PyObject *)st->st_cur) < 0)
st->st_errors++;
}
--- 4363,4371 ----
if (strcmp(name, TOP) == 0)
st->st_global = st->st_cur->ste_symbols;
! if (prev && st->st_pass == 1) {
if (PyList_Append(prev->ste_children,
(PyObject *)st->st_cur) < 0)
st->st_errors++;
+ }
}
Index: symtable.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/symtable.c,v
retrieving revision 2.1
retrieving revision 2.2
diff -C2 -r2.1 -r2.2
*** symtable.c 2001/02/09 22:22:18 2.1
--- symtable.c 2001/02/23 17:55:27 2.2
***************
*** 14,19 ****
goto fail;
v = PyDict_GetItem(st->st_symbols, k);
! if (v) /* XXX could check that name, type, lineno match */
! return v;
ste = (PySymtableEntryObject *)PyObject_New(PySymtableEntryObject,
--- 14,21 ----
goto fail;
v = PyDict_GetItem(st->st_symbols, k);
! if (v) /* XXX could check that name, type, lineno match */ {
! Py_INCREF(v);
! return v;
! }
ste = (PySymtableEntryObject *)PyObject_New(PySymtableEntryObject,
***************
*** 70,74 ****
if (PyDict_SetItem(st->st_symbols, ste->ste_id, (PyObject *)ste) < 0)
goto fail;
!
return (PyObject *)ste;
fail:
--- 72,76 ----
if (PyDict_SetItem(st->st_symbols, ste->ste_id, (PyObject *)ste) < 0)
goto fail;
!
return (PyObject *)ste;
fail: