Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1205afb

Browse files
bpo-40412: Nullify inittab_copy during finalization (GH-19746)
Otherwise we leave a dangling pointer to free'd memory. If we then initialize a new interpreter in the same process and call PyImport_ExtendInittab, we will (likely) crash when calling PyMem_RawRealloc(inittab_copy, ...) since the pointer address is bogus. Automerge-Triggered-By: @brettcannon (cherry picked from commit 64224a4) Co-authored-by: Gregory Szorc <[email protected]>
1 parent e058280 commit 1205afb

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Nullify inittab_copy during finalization, preventing future interpreter initializations in an embedded situation from crashing. Patch by Gregory Szorc.

Python/import.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ _PyImport_Fini2(void)
300300

301301
/* Free memory allocated by PyImport_ExtendInittab() */
302302
PyMem_RawFree(inittab_copy);
303+
inittab_copy = NULL;
303304

304305
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
305306
}

0 commit comments

Comments
 (0)