mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Correct memory leak
This commit is contained in:
@@ -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) {
|
||||
(*prg) = malloc(sizeof(struct dis_program_s));
|
||||
(*prg)->program = NULL;
|
||||
(*prg)->len = 0;
|
||||
(*prg)->pc = 0;
|
||||
}
|
||||
|
||||
static void dis_disassembler_deinit(dis_program_t **prg) {
|
||||
if((*prg)->program != NULL)
|
||||
free((*prg)->program);
|
||||
free((*prg));
|
||||
}
|
||||
@@ -469,7 +471,7 @@ static void dis_read_interpreter_sections(dis_program_t **prg, uint32_t *pc, uin
|
||||
printf("%d ", index);
|
||||
LIT_ADD(DIS_LITERAL_NULL, literal_type, literal_count);
|
||||
if (!(i % 15) && i != 0) {
|
||||
printf("\n");
|
||||
printf(" \\\n");
|
||||
if (!alt_fmt) {
|
||||
SPC(spaces);
|
||||
printf("| | ");
|
||||
@@ -507,7 +509,7 @@ static void dis_read_interpreter_sections(dis_program_t **prg, uint32_t *pc, uin
|
||||
printf("%d,%d ", key, val);
|
||||
|
||||
if (!(i % 5) && i != 0) {
|
||||
printf("\n");
|
||||
printf(" \\\n");
|
||||
if (!alt_fmt) {
|
||||
SPC(spaces);
|
||||
printf("| | ");
|
||||
@@ -707,11 +709,15 @@ void disassemble(const char *filename, bool alt_fmt) {
|
||||
queue_rear = NULL;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
dis_read_header(&prg, alt_fmt);
|
||||
|
||||
printf("\n.start MAIN\n");
|
||||
|
||||
consumeByte(DIS_OP_SECTION_END, prg->program, &(prg->pc));
|
||||
|
||||
if (alt_fmt)
|
||||
|
||||
Reference in New Issue
Block a user