summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter <zintensitydev@gmail.com>2024-06-21 17:28:19 (GMT)
committerGitHub <noreply@github.com>2024-06-21 17:28:19 (GMT)
commitaed31beca9a54b85a1392631a48da80602210f18 (patch)
tree5d53428f2569c1cdd110ba1424db908dcf8e2bf0
parenta81d434c06335b0989ba83666ec7076b9d9d4e1e (diff)
downloadcpython-aed31beca9a54b85a1392631a48da80602210f18.zip
cpython-aed31beca9a54b85a1392631a48da80602210f18.tar.gz
cpython-aed31beca9a54b85a1392631a48da80602210f18.tar.bz2
gh-120811: Fix reference leak upon `_PyContext_Exit` failure (#120812)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
-rw-r--r--Misc/NEWS.d/next/Library/2024-06-21-14-32-56.gh-issue-120811.eBmVTV.rst1
-rw-r--r--Python/context.c1
2 files changed, 2 insertions, 0 deletions
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 0000000..62cd7b5
--- /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 42000b1..a3830be 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;
}