threads: cleanup inconsistencies in memory management