avoid top-level pool release at codegen_error() and fixed some memory leaks