[M68K] printer_info need to be allocated only once

printer_info need to be allocated only once. cs_close() will cleanup for us.

Signed-off-by: Nicolas PLANEL <nplanel@gmail.com>
This commit is contained in:
Nicolas PLANEL 2015-10-05 21:56:39 +11:00
parent d529ea0db7
commit 44cc3d0c1e
2 changed files with 11 additions and 9 deletions

View File

@ -3869,12 +3869,18 @@ bool M68K_getInstruction(csh ud, const uint8_t* code, size_t code_len, MCInst* i
#endif
int s;
int cpu_type = M68K_CPU_TYPE_68000;
cs_struct* handle = (cs_struct *)(uintptr_t)ud;
cs_struct* handle = instr->csh;
m68k_info *info;
m68k_info *info = cs_mem_malloc(sizeof(m68k_info));
if (!info) {
handle->errnum = CS_ERR_MEM;
return false;
if (inst_info == NULL) {
info = cs_mem_malloc(sizeof(m68k_info));
if (!info) {
handle->errnum = CS_ERR_MEM;
return false;
}
handle->printer_info = info;
} else {
info = (m68k_info *)handle->printer_info;
}
info->code = code;
@ -3892,8 +3898,6 @@ bool M68K_getInstruction(csh ud, const uint8_t* code, size_t code_len, MCInst* i
cpu_type = M68K_CPU_TYPE_68040; // 060 = 040 for now
m68k_setup_internals(info, instr, address, cpu_type);
handle->printer_info = info;
s = m68k_disassemble(info, address);
if (s == 0) {

View File

@ -286,8 +286,6 @@ void M68K_printInst(MCInst* MI, SStream* O, void* PrinterInfo)
SStream_concat(O, ",%s", s_spacing);
}
#endif
cs_mem_free(PrinterInfo);
MI->csh->printer_info = NULL;
}
const char* M68K_reg_name(csh handle, unsigned int reg)