diff --git a/Misc/NEWS.d/next/Security/2023-01-14-23-51-57.gh-issue-101046.rRu9EP.rst b/Misc/NEWS.d/next/Security/2023-01-14-23-51-57.gh-issue-101046.rRu9EP.rst new file mode 100644 index 00000000000000..48344f003ab4ca --- /dev/null +++ b/Misc/NEWS.d/next/Security/2023-01-14-23-51-57.gh-issue-101046.rRu9EP.rst @@ -0,0 +1,2 @@ +Fix a potential memory leak when :func:`PyMem_Realloc` fails inside +:func:`_loop0_1_rule`. Patch by Ruili Fang diff --git a/Parser/parser.c b/Parser/parser.c index d0bc25927bece6..ae41226ef68903 100644 --- a/Parser/parser.c +++ b/Parser/parser.c @@ -23803,7 +23803,8 @@ _loop0_1_rule(Parser *p) _children_capacity *= 2; void **_new_children = PyMem_Realloc(_children, _children_capacity*sizeof(void *)); if (!_new_children) { - p->error_indicator = 1; + PyMem_Free(_children); + p->error_indicator = 1; PyErr_NoMemory(); p->level--; return NULL;