Skip to content

Commit 799cd48

Browse files
committed
gh-145301: Fix double-free in hmac module initialization
1 parent 157f397 commit 799cd48

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
Fix a double-free bug in :mod:`_hashlib` module initialization when
2-
``_Py_hashtable_set()`` fails while adding an algorithm alias to the hash
3-
table after the primary name was already added
1+
Fix a crash when :mod:`hashlib` or :mod:`hmac` C extension module initialization fails.

Modules/hmacmodule.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,10 @@ py_hmac_hinfo_ht_new(void)
14571457
do { \
14581458
int rc = py_hmac_hinfo_ht_add(table, KEY, value); \
14591459
if (rc < 0) { \
1460-
PyMem_Free(value); \
1460+
/* entry may already be in ht, will be freed by _Py_hashtable_destroy() */ \
1461+
if (value->refcnt == 0) { \
1462+
PyMem_Free(value); \
1463+
} \
14611464
goto error; \
14621465
} \
14631466
else if (rc == 1) { \

0 commit comments

Comments
 (0)