Uh oh!
There was an error while loading. Please reload this page.
gh-67877: Fix memory leaks in terminated RE matching - #126840
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.
serhiy-storchaka
commented
Nov 14, 2024
See also #126843. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
wjssz
commented
Nov 16, 2024
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. |
serhiy-storchaka
commented
Nov 18, 2024
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. |
wjssz
commented
Nov 19, 2024
|
…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.