Fixed a segfault when closing the application on OS X and Linux