Skip to content

Commit b471b4a

Browse files
[3.14] gh-151773: Fix NULL dereference in PyContextVar_Set (GH-151836) (#152010)
gh-151773: Fix NULL dereference in `PyContextVar_Set` (GH-151836) (cherry picked from commit d35b171) Co-authored-by: dev <b.chouksey27@gmail.com>
1 parent 79c06bd commit b471b4a

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash in :func:`contextvars.ContextVar.set` when memory allocation
2+
fails.

Python/context.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ PyContextVar_Set(PyObject *ovar, PyObject *val)
357357
Py_XINCREF(old_val);
358358
PyContextToken *tok = token_new(ctx, var, old_val);
359359
Py_XDECREF(old_val);
360+
if (tok == NULL) {
361+
return NULL;
362+
}
360363

361364
if (contextvar_set(var, val)) {
362365
Py_DECREF(tok);

0 commit comments

Comments
 (0)