Re: Memory leak in regex?

Guido.van.Rossum@cwi.nl
Sun, 22 Jan 1995 20:34:11 +0100

> # This loop seems to cause a memory leak
> # 1.1 sunos
> import regex
> while 1:
> print regex.match('test','test')
> print regex.match('xtest','xtest')

Thanks! The bug seems to be that the compiled pattern buffer is
never freed. Here's a fix -- lightly tested but seems okay so far.

===================================================================
RCS file: /ufs/guido/CVSROOT/python/Modules/regexmodule.c,v
retrieving revision 1.11
diff -c -r1.11 regexmodule.c
*** 1.11 1995/01/04 19:10:18
--- regexmodule.c 1995/01/22 19:28:12
***************
*** 57,62 ****
--- 57,63 ----
reg_dealloc(re)
regexobject *re;
{
+ XDEL(re->re_patbuf.buffer);
XDECREF(re->re_translate);
XDECREF(re->re_lastok);
XDECREF(re->re_groupindex);

--Guido van Rossum, CWI, Amsterdam <mailto:Guido.van.Rossum@cwi.nl>
<http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>