This caused X server to access free()'d memory on exit path. Thanks to msys.ch for providing a test machine.