Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e17384

Browse files
committed
Fix for #489672 (Neil Norwitz): memory leak in test_sre.
(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.
1 parent 202dd1e commit 4e17384

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

Modules/_sre.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,7 @@ pattern_subx(PatternObject* self, PyObject* template, PyObject* string,
21992199
goto error;
22002200
args = Py_BuildValue("(O)", match);
22012201
if (!args) {
2202-
Py_DECREF(args);
2202+
Py_DECREF(match);
22032203
goto error;
22042204
}
22052205
item = PyObject_CallObject(filter, args);
@@ -2246,6 +2246,8 @@ pattern_subx(PatternObject* self, PyObject* template, PyObject* string,
22462246

22472247
state_fini(&state);
22482248

2249+
Py_DECREF(filter);
2250+
22492251
/* convert list to single string (also removes list) */
22502252
item = join(list, self->pattern);
22512253

@@ -2258,6 +2260,7 @@ pattern_subx(PatternObject* self, PyObject* template, PyObject* string,
22582260
return item;
22592261

22602262
error:
2263+
Py_DECREF(filter);
22612264
Py_DECREF(list);
22622265
state_fini(&state);
22632266
return NULL;

0 commit comments

Comments
 (0)