Fix small memory leaks on shutdown