@@ -386,11 +386,15 @@ Initializing and finalizing the interpreter
386386 Undo all initializations made by :c:func:`Py_Initialize` and subsequent use of
387387 Python/C API functions, and destroy all sub-interpreters (see
388388 :c:func: `Py_NewInterpreter ` below) that were created and not yet destroyed since
389- the last call to :c:func:`Py_Initialize`. Ideally, this frees all memory
390- allocated by the Python interpreter. This is a no-op when called for a second
389+ the last call to :c:func:`Py_Initialize`. This is a no-op when called for a second
391390 time (without calling :c:func: `Py_Initialize ` again first). Normally the
392391 return value is ``0``. If there were errors during finalization
393392 (flushing buffered data), ``-1`` is returned.
393+
394+ Note that Python will do a best effort at freeing all memory allocated by the Python
395+ interpreter. Therefore, any C-Extension should make sure to correctly clean up all
396+ of the preveiously allocated PyObjects before using them in subsequent calls to
397+ `Py_Initialize`. Otherwise it introduces vulnerabilities and incorrect behavior.
394398
395399 This function is provided for a number of reasons. An embedding application
396400 might want to restart Python without having to restart the application itself.
@@ -406,10 +410,11 @@ Initializing and finalizing the interpreter
406410 loaded extension modules loaded by Python are not unloaded. Small amounts of
407411 memory allocated by the Python interpreter may not be freed (if you find a leak,
408412 please report it). Memory tied up in circular references between objects is not
409- freed. Some memory allocated by extension modules may not be freed. Some
410- extensions may not work properly if their initialization routine is called more
411- than once; this can happen if an application calls :c:func:`Py_Initialize` and
412- :c:func: `Py_FinalizeEx ` more than once.
413+ freed. Interned strings will all be deallocated regarldess of their reference count.
414+ Some memory allocated by extension modules may not be freed. Some extensions may not
415+ work properly if their initialization routine is called more than once; this can
416+ happen if an application calls :c:func: `Py_Initialize ` and :c:func: `Py_FinalizeEx `
417+ more than once.
413418
414419 .. audit-event :: cpython._PySys_ClearAuditHooks "" c.Py_FinalizeEx
415420
0 commit comments