Fix assert on exit when compiled in debug mode