• Ben Avison's avatar
    Work around free failure on finalisation if module re-entered · 2788f039
    Ben Avison authored
    During module finalisation, we call fclose(), and one of the things this does
    if to attempt to free() a pointer from the application heap. For reasons not
    entirely clear, the pointer is not valid if the module entry point has been
    called more than once, and this results in free() failing noisily.
    
    However, it's also obvious that we shouldn't be attempting to manipulate the
    application heap from module finalisation, as we may not even have our own
    application slot mapped in at the time. So the workaround presented here is
    to skip the free() if we are not in USR mode.
    2788f039