Skip to content

Commit b88da92

Browse files
bhuvi27miss-islington
authored andcommitted
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 771d12d commit b88da92

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
@@ -278,6 +278,9 @@ PyContextVar_Set(PyObject *ovar, PyObject *val)
278278
Py_XINCREF(old_val);
279279
PyContextToken *tok = token_new(ctx, var, old_val);
280280
Py_XDECREF(old_val);
281+
if (tok == NULL) {
282+
return NULL;
283+
}
281284

282285
if (contextvar_set(var, val)) {
283286
Py_DECREF(tok);

0 commit comments

Comments
 (0)