Skip to content

Commit d35b171

Browse files
authored
gh-151773: Fix NULL dereference in PyContextVar_Set (#151836)
1 parent 5858e42 commit d35b171

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)