Skip to content

Commit 7b765a4

Browse files
[3.15] gh-151773: Fix NULL dereference in PyContextVar_Set (GH-151836) (#152009)
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 672825e commit 7b765a4

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
@@ -362,6 +362,9 @@ PyContextVar_Set(PyObject *ovar, PyObject *val)
362362
Py_XINCREF(old_val);
363363
PyContextToken *tok = token_new(ctx, var, old_val);
364364
Py_XDECREF(old_val);
365+
if (tok == NULL) {
366+
return NULL;
367+
}
365368

366369
if (contextvar_set(var, val)) {
367370
Py_DECREF(tok);

0 commit comments

Comments
 (0)