Test and fix parser memory leaks and double frees