fixed memory leaks in generated code