Skip to content

Commit 4080019

Browse files
committed
Fix _PyCode_New() failure cleanup for co_tlbc and replacement_locations
1 parent 9242700 commit 4080019

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Objects/codeobject.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ _PyCode_New(struct _PyCodeConstructor *con)
744744
}
745745

746746
if (init_code(co, con) < 0) {
747+
Py_XDECREF(replacement_locations);
747748
Py_DECREF(co);
748749
return NULL;
749750
}
@@ -2451,13 +2452,15 @@ code_dealloc(PyObject *self)
24512452
#ifdef Py_GIL_DISABLED
24522453
// The first element always points to the mutable bytecode at the end of
24532454
// the code object, which will be freed when the code object is freed.
2454-
for (Py_ssize_t i = 1; i < co->co_tlbc->size; i++) {
2455-
char *entry = co->co_tlbc->entries[i];
2456-
if (entry != NULL) {
2457-
PyMem_Free(entry);
2455+
if (co->co_tlbc != NULL) {
2456+
for (Py_ssize_t i = 1; i < co->co_tlbc->size; i++) {
2457+
char *entry = co->co_tlbc->entries[i];
2458+
if (entry != NULL) {
2459+
PyMem_Free(entry);
2460+
}
24582461
}
2462+
PyMem_Free(co->co_tlbc);
24592463
}
2460-
PyMem_Free(co->co_tlbc);
24612464
#endif
24622465
PyObject_Free(co);
24632466
}

0 commit comments

Comments
 (0)