[CODEGEN] Fix leaks with codegen