[3.13] gh-140530: fix a reference leak in an error path for raise exc 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 exception
subtype for which `T.__new__` does not return an exception instance.

(cherry picked from commit 0c77e7c23b)
This commit is contained in:
Bénédikt Tran 2025-11-09 15:57:26 +01:00 committed by GitHub
parent 873f0d023c
commit 718886f6c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 11 deletions

View file

@ -1962,6 +1962,7 @@ do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause)
"calling %R should have returned an instance of "
"BaseException, not %R",
cause, Py_TYPE(fixed_cause));
Py_DECREF(fixed_cause);
goto raise_error;
}
Py_DECREF(cause);