]> granicus.if.org Git - python/commitdiff
Fix for #489672 (Neil Norwitz): memory leak in test_sre.
authorGuido van Rossum <guido@python.org>
Fri, 7 Dec 2001 04:25:10 +0000 (04:25 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 7 Dec 2001 04:25:10 +0000 (04:25 +0000)
(At least for the repeatable test case that Tim produced.)

pattern_subx(): Add missing DECREF(filter) in both exit branches
(normal and error return).  Also fix a DECREF(args) that should
certainly be a DECREF(match) -- because it's inside if (!args) and
right after allocation of match.

Modules/_sre.c

index c78ed52c421c14bd965776c4b0da7c40577187e1..d01f087cde031e1698bcb31f8d87eb4671c65da5 100644 (file)
@@ -2199,7 +2199,7 @@ pattern_subx(PatternObject* self, PyObject* template, PyObject* string,
                 goto error;
             args = Py_BuildValue("(O)", match);
             if (!args) {
-                Py_DECREF(args);
+                Py_DECREF(match);
                 goto error;
             }
             item = PyObject_CallObject(filter, args);
@@ -2246,6 +2246,8 @@ next:
 
     state_fini(&state);
 
+    Py_DECREF(filter);
+
     /* convert list to single string (also removes list) */
     item = join(list, self->pattern);
 
@@ -2258,6 +2260,7 @@ next:
     return item;
 
 error:
+    Py_DECREF(filter);
     Py_DECREF(list);
     state_fini(&state);
     return NULL;