Fix segfault on application exit on Windows