gh-67877: Fix memory leaks in terminated RE matching#126840
gh-67877: Fix memory leaks in terminated RE matching#126840serhiy-storchaka merged 5 commits intopython:mainfrom
Conversation
If SRE(match) function terminates abruptly, either because of a signal or because memory allocation fails, allocated SRE_REPEAT blocks might be never released.
|
See also #126843. |
|
Looks good to me. |
| do { \ | ||
| _MAYBE_CHECK_SIGNALS; \ | ||
| if (state->fail_after_count >= 0) { \ | ||
| if (state->fail_after_count-- == 0) { \ |
There was a problem hiding this comment.
Setting state->fail_after_count does not affect subsequent calls of the Pattern methods, but it still affects the finditer() iterator which reuses state between iterations.
There was a problem hiding this comment.
I deleted my previous reply.
Maybe setting state->fail_after_count = -1 doesn't make sense, it's better to make the finditer() iterator stop the subsequent matchings.
|
I remember another thing, if this patch is going to be backported, you may remove the changes related to this: - PyObject* pattern;
+ PatternObject* pattern;The patch will be smaller and clearer. |
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12, 3.13. |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
GH-126960 is a backport of this pull request to the 3.13 branch. |
…thonGH-126840) If SRE(match) function terminates abruptly, either because of a signal or because memory allocation fails, allocated SRE_REPEAT blocks might be never released. (cherry picked from commit 7538e7f) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: <wjssz@users.noreply.github.com>
|
GH-126961 is a backport of this pull request to the 3.12 branch. |
It is easier to not do. I can introduce new bugs when trying to remove these changes in backports. Initially it was needed to pass the second argument to state_fini, after reverting that change it is just a clean up, but it can still be helpful if in future we will need to pass the second argument to state_fini. |
|
|
…126840) If SRE(match) function terminates abruptly, either because of a signal or because memory allocation fails, allocated SRE_REPEAT blocks might be never released. Co-authored-by: <wjssz@users.noreply.github.com>
If SRE(match) function terminates abruptly, either because of a signal or because memory allocation fails, allocated SRE_REPEAT blocks might be never released.