-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.