Fix memory deallocation race condition which occurred at program exit, lower number of memory leaks at program exit