Fix segfault on exit for OSX