Fix for annoying intermittent seg fault on Linux exit.  Closes #2542.