Fix memory leak

This commit is contained in:
Dmitry Stogov 2022-12-26 14:17:48 +03:00
parent 844653cfd1
commit 1df594fea5
2 changed files with 12 additions and 0 deletions

View File

@ -5259,11 +5259,16 @@ const void *ir_emit_exitgroup(uint32_t first_exit_point, uint32_t exit_points_pe
ret = dasm_link(&dasm_state, &size);
if (ret != DASM_S_OK) {
IR_ASSERT(0);
dasm_free(&data.dasm_state);
if (code_buffer == NULL) {
ir_mem_unmap(entry, size);
}
return NULL;
}
if (code_buffer != NULL) {
if (IR_ALIGNED_SIZE(size, 16) > code_buffer_size) {
dasm_free(&data.dasm_state);
return NULL;
}
entry = code_buffer;
@ -5276,6 +5281,7 @@ const void *ir_emit_exitgroup(uint32_t first_exit_point, uint32_t exit_points_pe
ret = dasm_encode(&dasm_state, entry);
if (ret != DASM_S_OK) {
IR_ASSERT(0);
dasm_free(&data.dasm_state);
if (code_buffer == NULL) {
ir_mem_unmap(entry, size);
}

View File

@ -8042,12 +8042,17 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr)
ret = dasm_link(&data.dasm_state, size_ptr);
if (ret != DASM_S_OK) {
IR_ASSERT(0);
dasm_free(&data.dasm_state);
if (ctx->code_buffer == NULL) {
ir_mem_unmap(entry, size);
}
return NULL;
}
size = *size_ptr;
if (ctx->code_buffer != NULL) {
if (IR_ALIGNED_SIZE(size, 16) > ctx->code_buffer_size) {
dasm_free(&data.dasm_state);
return NULL;
}
entry = ctx->code_buffer;
@ -8060,6 +8065,7 @@ void *ir_emit_code(ir_ctx *ctx, size_t *size_ptr)
ret = dasm_encode(&data.dasm_state, entry);
if (ret != DASM_S_OK) {
IR_ASSERT(0);
dasm_free(&data.dasm_state);
if (ctx->code_buffer == NULL) {
ir_mem_unmap(entry, size);
}