Skip to content

Commit

Permalink
bpo-40412: Nullify inittab_copy during finalization (pythonGH-19746)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
indygreg authored May 1, 2020
1 parent 831d58d commit 64224a4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Nullify inittab_copy during finalization, preventing future interpreter initializations in an embedded situation from crashing. Patch by Gregory Szorc.
1 change: 1 addition & 0 deletions Python/import.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ _PyImport_Fini2(void)

/* Free memory allocated by PyImport_ExtendInittab() */
PyMem_RawFree(inittab_copy);
inittab_copy = NULL;

PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
}
Expand Down

0 comments on commit 64224a4

Please sign in to comment.