Skip to content

Commit

Permalink
Fix leak of procedure context structures
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Dec 23, 2012
1 parent 92204dc commit a16dd20
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/cgen.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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()));
}

Expand Down

0 comments on commit a16dd20

Please sign in to comment.