[Python-Dev] compile leaks memory. lots of memory.

Martin von Loewis loewis@informatik.hu-berlin.de
Thu, 22 Feb 2001 18:57:49 +0100 (MET)


> It would be helpful to get some analysis on this known problem
> before the beta release.

It looks like there is a leak of symtable entries. In particular,
symtable_enter_scope has

	if (st->st_cur) {
		prev = st->st_cur;
		if (PyList_Append(st->st_stack, (PyObject *)st->st_cur) < 0) {
			Py_DECREF(st->st_cur);
			st->st_errors++;
			return;
		}
	}
	st->st_cur = (PySymtableEntryObject *)\
		PySymtableEntry_New(st, name, type, lineno);
	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++;

First, it seems that

         Py_XDECREF(prev);

is missing. That alone does not fix the leak, though, since prev is
always null in the test case.

The real problem comes from st_cur never being released, AFAICT. There
is a DECREF in symtable_exit_scope, but that function is not called in
the test case - symtable_enter_scope is called. For symmetry reasons,
it appears that there should be a call to symtable_exit_scope of the
global scope somewhere (which apparently is build in symtable_build).
I can't figure how what the correct place for that call would be,
though.

Regards,
Martin