Permalink
Browse files

Fix leak of procedure context structures

  • Loading branch information...
1 parent 92204dc commit a16dd206a2d20bb460b9c6bc602c9fe9939c1fec @nickg committed Dec 23, 2012
Showing with 12 additions and 1 deletion.
  1. +12 −1 src/cgen.c
View
@@ -2244,8 +2244,14 @@ static void cgen_return(tree_t t, cgen_ctx_t *ctx)
else
LLVMBuildRet(builder, rval);
}
- else
+ else {
+ if (ctx->state != NULL) {
+ // Free the dynamic context
+ LLVMBuildFree(builder, LLVMBuildStructGEP(builder, ctx->state, 0, ""));
+ }
+
LLVMBuildRet(builder, LLVMConstNull(llvm_void_ptr()));
+ }
LLVMBasicBlockRef unreach_bb = LLVMAppendBasicBlock(ctx->fn, "unreach");
LLVMPositionBuilderAtEnd(builder, unreach_bb);
@@ -3198,6 +3204,11 @@ static void cgen_proc_body(tree_t t)
for (unsigned i = 0; i < tree_stmts(t); i++)
cgen_stmt(tree_stmt(t, i), &ctx);
+ if (ctx.state != NULL) {
+ // Free the dynamic context
+ LLVMBuildFree(builder, LLVMBuildStructGEP(builder, ctx.state, 0, ""));
+ }
+
LLVMBuildRet(builder, LLVMConstNull(llvm_void_ptr()));
}

0 comments on commit a16dd20

Please sign in to comment.