Fix memory leak in code_gen_buffer
This commit is contained in:
@@ -879,16 +879,18 @@ static inline void *alloc_code_gen_buffer(struct uc_struct *uc)
|
|||||||
void free_code_gen_buffer(struct uc_struct *uc)
|
void free_code_gen_buffer(struct uc_struct *uc)
|
||||||
{
|
{
|
||||||
TCGContext *tcg_ctx = uc->tcg_ctx;
|
TCGContext *tcg_ctx = uc->tcg_ctx;
|
||||||
if (tcg_ctx->code_gen_buffer) {
|
if (tcg_ctx->initial_buffer) {
|
||||||
VirtualFree(tcg_ctx->code_gen_buffer, 0, MEM_RELEASE);
|
VirtualFree(tcg_ctx->initial_buffer, 0, MEM_RELEASE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void free_code_gen_buffer(struct uc_struct *uc)
|
void free_code_gen_buffer(struct uc_struct *uc)
|
||||||
{
|
{
|
||||||
TCGContext *tcg_ctx = uc->tcg_ctx;
|
TCGContext *tcg_ctx = uc->tcg_ctx;
|
||||||
if (tcg_ctx->code_gen_buffer) {
|
if (tcg_ctx->initial_buffer) {
|
||||||
munmap(tcg_ctx->code_gen_buffer, tcg_ctx->code_gen_buffer_size);
|
if (munmap(tcg_ctx->initial_buffer, tcg_ctx->initial_buffer_size)) {
|
||||||
|
perror("fail code_gen_buffer");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -953,6 +955,8 @@ static inline void code_gen_alloc(struct uc_struct *uc, size_t tb_size)
|
|||||||
TCGContext *tcg_ctx = uc->tcg_ctx;
|
TCGContext *tcg_ctx = uc->tcg_ctx;
|
||||||
tcg_ctx->code_gen_buffer_size = size_code_gen_buffer(tb_size);
|
tcg_ctx->code_gen_buffer_size = size_code_gen_buffer(tb_size);
|
||||||
tcg_ctx->code_gen_buffer = alloc_code_gen_buffer(uc);
|
tcg_ctx->code_gen_buffer = alloc_code_gen_buffer(uc);
|
||||||
|
tcg_ctx->initial_buffer = tcg_ctx->code_gen_buffer;
|
||||||
|
tcg_ctx->initial_buffer_size = tcg_ctx->code_gen_buffer_size;
|
||||||
if (tcg_ctx->code_gen_buffer == NULL) {
|
if (tcg_ctx->code_gen_buffer == NULL) {
|
||||||
fprintf(stderr, "Could not allocate dynamic translator buffer\n");
|
fprintf(stderr, "Could not allocate dynamic translator buffer\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|||||||
@@ -642,6 +642,8 @@ struct TCGContext {
|
|||||||
void *code_gen_prologue;
|
void *code_gen_prologue;
|
||||||
void *code_gen_epilogue;
|
void *code_gen_epilogue;
|
||||||
void *code_gen_buffer;
|
void *code_gen_buffer;
|
||||||
|
void *initial_buffer;
|
||||||
|
size_t initial_buffer_size;
|
||||||
size_t code_gen_buffer_size;
|
size_t code_gen_buffer_size;
|
||||||
void *code_gen_ptr;
|
void *code_gen_ptr;
|
||||||
void *data_gen_ptr;
|
void *data_gen_ptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user