Fix case where in certain SAPIs the current directory changes after
a fatal error