Fix thread memory leaks
Removed tmp file