Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-140530: fix a reference leak in an error path forraise exc from cause#140908

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
picnixz merged 1 commit intopython:mainfrompicnixz:fix/core/raise-from-140530
Nov 9, 2025

Conversation

@picnixz
Copy link
Member

@picnixzpicnixz commentedNov 2, 2025
edited by bedevere-appbot
Loading

subtype for which `T.__new__` does not return an exception instance.
@picnixzpicnixzforce-pushed thefix/core/raise-from-140530 branch froma445dd3 toadb1bc4CompareNovember 2, 2025 11:54
@picnixzpicnixz added the 🔨 test-with-refleak-buildbotsTest PR w/ refleak buildbots; report in status section labelNov 2, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@picnixz for commitadb1bc4 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F140908%2Fmerge

If you want to schedule another build, you need to add the🔨 test-with-refleak-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-refleak-buildbotsTest PR w/ refleak buildbots; report in status section labelNov 2, 2025
@picnixzpicnixz added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes labelsNov 2, 2025
self.fail("No exception raised")

deftest_class_cause_nonexception_result(self):
classConstructsNone(BaseException):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we should keep the old test and add the new test in?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The old test is actually testing the same code. The problem was that the returned value was immortal...

efimov-mikhail reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

FTR:

if (PyExceptionClass_Check(cause)) {fixed_cause=_PyObject_CallNoArgs(cause);if (fixed_cause==NULL)gotoraise_error;if (!PyExceptionInstance_Check(fixed_cause)) {_PyErr_Format(tstate,PyExc_TypeError,"calling %R should have returned an instance of ""BaseException, not %R",cause,Py_TYPE(fixed_cause));Py_DECREF(fixed_cause);gotoraise_error;}Py_DECREF(cause);}

Sincecause is an exception class, we called__new__ andfixed_cause would have beenNone. We would then move toPyExceptionInstance_Check but sincefixed_cause is immortal the refleak didn't appear.

efimov-mikhail reacted with thumbs up emoji
Py_DECREF(fixed_cause);
gotoraise_error;
}
Py_DECREF(cause);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Just checking so I'm clear:PyException_SetCause steals a reference right? That's why we're not decrefingfixed_cause here?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

AFAIR, yes.PyException_Set* always steal refs IIRC, but I will check this again (it's always a pain to remember which function steals or borrows)

Copy link
Member

@efimov-mikhailefimov-mikhailNov 9, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes,PyException_SetCause steals a reference tocause:

/* Steals a reference to cause */
void
PyException_SetCause(PyObject*self,PyObject*cause)
{

Copy link
Member

@efimov-mikhailefimov-mikhail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM

@picnixzpicnixz merged commit0c77e7c intopython:mainNov 9, 2025
71 checks passed
@picnixzpicnixz deleted the fix/core/raise-from-140530 branchNovember 9, 2025 12:41
@miss-islington-app
Copy link

Thanks@picnixz for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestNov 9, 2025
… from cause` (pythonGH-140908)Fix a reference leak in `raise E from T` when `T` is an exceptionsubtype for which `T.__new__` does not return an exception instance.(cherry picked from commit0c77e7c)Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@miss-islington-app
Copy link

Sorry,@picnixz, I could not cleanly backport this to3.13 due to a conflict.
Please backport usingcherry_picker on command line.

cherry_picker 0c77e7c23b5c270a3142105542c56c59b59c52a0 3.13

@bedevere-app
Copy link

GH-141282 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelNov 9, 2025
@bedevere-app
Copy link

GH-141283 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelNov 9, 2025
picnixz added a commit that referenced this pull requestNov 9, 2025
…c from cause` (GH-140908) (#141283)gh-140530: fix a reference leak in an error path for `raise exc from cause` (#140908)Fix a reference leak in `raise E from T` when `T` is an exceptionsubtype for which `T.__new__` does not return an exception instance.(cherry picked from commit0c77e7c)
picnixz added a commit that referenced this pull requestNov 9, 2025
…c from cause` (GH-140908) (#141282)gh-140530: fix a reference leak in an error path for `raise exc from cause` (GH-140908)Fix a reference leak in `raise E from T` when `T` is an exceptionsubtype for which `T.__new__` does not return an exception instance.(cherry picked from commit0c77e7c)Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@Fidget-SpinnerFidget-SpinnerFidget-Spinner left review comments

@efimov-mikhailefimov-mikhailefimov-mikhail approved these changes

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

Assignees

@picnixzpicnixz

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@picnixz@bedevere-bot@efimov-mikhail@Fidget-Spinner

[8]ページ先頭

©2009-2025 Movatter.jp