Fix strange memory leaks