diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2025-04-02 12:05:30 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-02 12:05:30 (GMT) |
| commit | b3cf1f27e94d65eba4ed300bdf5851c0326a2a44 (patch) | |
| tree | db8fb5edf5c6622840d8553217553fbf8238e4f4 /Python | |
| parent | afb3f33256c2f74c560c70ac00514722f177a1db (diff) | |
| download | cpython-b3cf1f27e94d65eba4ed300bdf5851c0326a2a44.zip cpython-b3cf1f27e94d65eba4ed300bdf5851c0326a2a44.tar.gz cpython-b3cf1f27e94d65eba4ed300bdf5851c0326a2a44.tar.bz2 | |
[3.12] gh-132002: Fix crash of `ContextVar` on unhashable `str` subtype (GH-132003) (#132008)
gh-132002: Fix crash of `ContextVar` on unhashable `str` subtype (GH-132003)
(cherry picked from commit ab2a3dda1d3b6668162a847bf5b6aca2855a3416)
Co-authored-by: sobolevn <mail@sobolevn.me>
Diffstat (limited to 'Python')
| -rw-r--r-- | Python/context.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/Python/context.c b/Python/context.c index 7bccfad..e589921 100644 --- a/Python/context.c +++ b/Python/context.c @@ -821,20 +821,19 @@ contextvar_new(PyObject *name, PyObject *def) return NULL; } - var->var_hash = contextvar_generate_hash(var, name); - if (var->var_hash == -1) { - Py_DECREF(var); - return NULL; - } - var->var_name = Py_NewRef(name); - var->var_default = Py_XNewRef(def); var->var_cached = NULL; var->var_cached_tsid = 0; var->var_cached_tsver = 0; + var->var_hash = contextvar_generate_hash(var, name); + if (var->var_hash == -1) { + Py_DECREF(var); + return NULL; + } + if (_PyObject_GC_MAY_BE_TRACKED(name) || (def != NULL && _PyObject_GC_MAY_BE_TRACKED(def))) { |
