Correct memory leak

This commit is contained in:
hiperiondev
2023-08-22 20:21:43 -03:00
parent b5883e248b
commit d8c6a3ec27

View File

@@ -222,11 +222,13 @@ static void consumeByte(uint8_t byte, uint8_t *tb, uint32_t *count) {
static void dis_disassembler_init(dis_program_t **prg) { static void dis_disassembler_init(dis_program_t **prg) {
(*prg) = malloc(sizeof(struct dis_program_s)); (*prg) = malloc(sizeof(struct dis_program_s));
(*prg)->program = NULL;
(*prg)->len = 0; (*prg)->len = 0;
(*prg)->pc = 0; (*prg)->pc = 0;
} }
static void dis_disassembler_deinit(dis_program_t **prg) { static void dis_disassembler_deinit(dis_program_t **prg) {
if((*prg)->program != NULL)
free((*prg)->program); free((*prg)->program);
free((*prg)); free((*prg));
} }
@@ -469,7 +471,7 @@ static void dis_read_interpreter_sections(dis_program_t **prg, uint32_t *pc, uin
printf("%d ", index); printf("%d ", index);
LIT_ADD(DIS_LITERAL_NULL, literal_type, literal_count); LIT_ADD(DIS_LITERAL_NULL, literal_type, literal_count);
if (!(i % 15) && i != 0) { if (!(i % 15) && i != 0) {
printf("\n"); printf(" \\\n");
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| | "); printf("| | ");
@@ -507,7 +509,7 @@ static void dis_read_interpreter_sections(dis_program_t **prg, uint32_t *pc, uin
printf("%d,%d ", key, val); printf("%d,%d ", key, val);
if (!(i % 5) && i != 0) { if (!(i % 5) && i != 0) {
printf("\n"); printf(" \\\n");
if (!alt_fmt) { if (!alt_fmt) {
SPC(spaces); SPC(spaces);
printf("| | "); printf("| | ");
@@ -707,11 +709,15 @@ void disassemble(const char *filename, bool alt_fmt) {
queue_rear = NULL; queue_rear = NULL;
dis_disassembler_init(&prg); dis_disassembler_init(&prg);
if (dis_load_file(filename, &prg, alt_fmt)) if (dis_load_file(filename, &prg, alt_fmt)) {
dis_disassembler_deinit(&prg);
exit(1); exit(1);
}
dis_read_header(&prg, alt_fmt); dis_read_header(&prg, alt_fmt);
printf("\n.start MAIN\n");
consumeByte(DIS_OP_SECTION_END, prg->program, &(prg->pc)); consumeByte(DIS_OP_SECTION_END, prg->program, &(prg->pc));
if (alt_fmt) if (alt_fmt)