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

Skip to content

Commit 64224a4

Browse files
authored
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
1 parent 831d58d commit 64224a4

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
@@ -298,6 +298,7 @@ _PyImport_Fini2(void)
298298

299299
/* Free memory allocated by PyImport_ExtendInittab() */
300300
PyMem_RawFree(inittab_copy);
301+
inittab_copy = NULL;
301302

302303
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
303304
}

0 commit comments

Comments
 (0)