]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151773: Fix NULL dereference in `PyContextVar_Set` (#151836)
authordev <b.chouksey27@gmail.com>
Tue, 23 Jun 2026 14:15:15 +0000 (19:45 +0530)
committerGitHub <noreply@github.com>
Tue, 23 Jun 2026 14:15:15 +0000 (17:15 +0300)
Misc/NEWS.d/next/Core_and_Builtins/2026-06-21-16-00-00.gh-issue-151773.mN4kRt.rst [new file with mode: 0644]
Python/context.c

diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-21-16-00-00.gh-issue-151773.mN4kRt.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-21-16-00-00.gh-issue-151773.mN4kRt.rst
new file mode 100644 (file)
index 0000000..b4193c5
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a crash in :func:`contextvars.ContextVar.set` when memory allocation
+fails.
index 593e6ef90037cfa90dd15a236ee4fe6963c3bc7f..4678054ff3ad74360ec304cf75aeb670e49159cf 100644 (file)
@@ -362,6 +362,9 @@ PyContextVar_Set(PyObject *ovar, PyObject *val)
     Py_XINCREF(old_val);
     PyContextToken *tok = token_new(ctx, var, old_val);
     Py_XDECREF(old_val);
+    if (tok == NULL) {
+        return NULL;
+    }
 
     if (contextvar_set(var, val)) {
         Py_DECREF(tok);