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
64224a4727321a8dd33e6f769edda401193ebef0)
Co-authored-by: Gregory Szorc <gregory.szorc@gmail.com>
--- /dev/null
+Nullify inittab_copy during finalization, preventing future interpreter initializations in an embedded situation from crashing. Patch by Gregory Szorc.
/* Free memory allocated by PyImport_ExtendInittab() */
PyMem_RawFree(inittab_copy);
+ inittab_copy = NULL;
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
}