Memory leak detection bugfixes for multi-threading.