Skip to content

Commit 967238f

Browse files
authored
Fix memory leaks. (#328)
Change-Id: Ic5262101b1a572cfcf91f29f813a24df3899fd0c
1 parent f042dcb commit 967238f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/flash/nor/fespi.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ static struct algorithm_steps *as_delete(struct algorithm_steps *as)
501501
free(as->steps[step]);
502502
as->steps[step] = NULL;
503503
}
504+
free(as->steps);
504505
free(as);
505506
return NULL;
506507
}
@@ -695,17 +696,19 @@ static int steps_execute(struct algorithm_steps *as,
695696
init_reg_param(&reg_params[1], "a1", xlen, PARAM_OUT);
696697
buf_set_u64(reg_params[0].value, 0, xlen, ctrl_base);
697698
buf_set_u64(reg_params[1].value, 0, xlen, data_wa->address);
699+
700+
int retval = ERROR_OK;
698701
while (!as_empty(as)) {
699702
keep_alive();
700703
uint8_t *data_buf = malloc(data_wa->size);
701704
unsigned bytes = as_compile(as, data_buf, data_wa->size);
702-
int retval = target_write_buffer(target, data_wa->address, bytes,
705+
retval = target_write_buffer(target, data_wa->address, bytes,
703706
data_buf);
704707
free(data_buf);
705708
if (retval != ERROR_OK) {
706709
LOG_ERROR("Failed to write data to 0x%" TARGET_PRIxADDR ": %d",
707710
data_wa->address, retval);
708-
return retval;
711+
goto exit;
709712
}
710713

711714
retval = target_run_algorithm(target, 0, NULL, 2, reg_params,
@@ -714,11 +717,14 @@ static int steps_execute(struct algorithm_steps *as,
714717
if (retval != ERROR_OK) {
715718
LOG_ERROR("Failed to execute algorithm at 0x%" TARGET_PRIxADDR ": %d",
716719
algorithm_wa->address, retval);
717-
return retval;
720+
goto exit;
718721
}
719722
}
720723

721-
return ERROR_OK;
724+
exit:
725+
destroy_reg_param(&reg_params[1]);
726+
destroy_reg_param(&reg_params[0]);
727+
return retval;
722728
}
723729

724730
static int fespi_write(struct flash_bank *bank, const uint8_t *buffer,

0 commit comments

Comments
 (0)