Add missing codes that can be caught by register_shutdown_function

Proposition for #6346

Will try and provide test if approved.