• Victor Stinner's avatar
    Close #16742: Fix misuse of memory allocations in PyOS_Readline() · 2fe9bac4
    Victor Stinner authored
    The GIL must be held to call PyMem_Malloc(), whereas PyOS_Readline() releases
    the GIL to read input.
    
    The result of the C callback PyOS_ReadlineFunctionPointer must now be a string
    allocated by PyMem_RawMalloc() or PyMem_RawRealloc() (or NULL if an error
    occurred), instead of a string allocated by PyMem_Malloc() or PyMem_Realloc().
    
    Fixing this issue was required to setup a hook on PyMem_Malloc(), for example
    using the tracemalloc module.
    
    PyOS_Readline() copies the result of PyOS_ReadlineFunctionPointer() into a new
    buffer allocated by PyMem_Malloc(). So the public API of PyOS_Readline() does
    not change.
    2fe9bac4
veryhigh.rst 15.7 KB