fix errno on exit