From 680e76d478973d4ecd226f8a87ae836c76084f5a Mon Sep 17 00:00:00 2001 From: Peter Date: Fri, 21 Jun 2024 12:28:19 -0500 Subject: [PATCH] gh-120811: Fix reference leak upon `_PyContext_Exit` failure (GH-120812) (cherry picked from commit aed31beca9a54b85a1392631a48da80602210f18) Co-authored-by: Peter Co-authored-by: Kumar Aditya --- .../next/Library/2024-06-21-14-32-56.gh-issue-120811.eBmVTV.rst | 1 + Python/context.c | 1 + 2 files changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-06-21-14-32-56.gh-issue-120811.eBmVTV.rst diff --git a/Misc/NEWS.d/next/Library/2024-06-21-14-32-56.gh-issue-120811.eBmVTV.rst b/Misc/NEWS.d/next/Library/2024-06-21-14-32-56.gh-issue-120811.eBmVTV.rst new file mode 100644 index 00000000000000..62cd7b5620474a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-06-21-14-32-56.gh-issue-120811.eBmVTV.rst @@ -0,0 +1 @@ +Fix possible memory leak in :meth:`contextvars.Context.run`. diff --git a/Python/context.c b/Python/context.c index 3937819b3c386c..63318d1e597439 100644 --- a/Python/context.c +++ b/Python/context.c @@ -661,6 +661,7 @@ context_run(PyContext *self, PyObject *const *args, ts, args[0], args + 1, nargs - 1, kwnames); if (_PyContext_Exit(ts, (PyObject *)self)) { + Py_XDECREF(call_result); return NULL; }