minor refactoring, free allocated memory in case of parse errors