Fix memory leaks. (#328)

Change-Id: Ic5262101b1a572cfcf91f29f813a24df3899fd0c
deinit
Tim Newsome 2018-11-12 13:02:11 -08:00 committed by GitHub
parent f042dcb0a3
commit 967238fb6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 4 deletions

View File

@ -501,6 +501,7 @@ static struct algorithm_steps *as_delete(struct algorithm_steps *as)
free(as->steps[step]);
as->steps[step] = NULL;
}
free(as->steps);
free(as);
return NULL;
}
@ -695,17 +696,19 @@ static int steps_execute(struct algorithm_steps *as,
init_reg_param(&reg_params[1], "a1", xlen, PARAM_OUT);
buf_set_u64(reg_params[0].value, 0, xlen, ctrl_base);
buf_set_u64(reg_params[1].value, 0, xlen, data_wa->address);
int retval = ERROR_OK;
while (!as_empty(as)) {
keep_alive();
uint8_t *data_buf = malloc(data_wa->size);
unsigned bytes = as_compile(as, data_buf, data_wa->size);
int retval = target_write_buffer(target, data_wa->address, bytes,
retval = target_write_buffer(target, data_wa->address, bytes,
data_buf);
free(data_buf);
if (retval != ERROR_OK) {
LOG_ERROR("Failed to write data to 0x%" TARGET_PRIxADDR ": %d",
data_wa->address, retval);
return retval;
goto exit;
}
retval = target_run_algorithm(target, 0, NULL, 2, reg_params,
@ -714,11 +717,14 @@ static int steps_execute(struct algorithm_steps *as,
if (retval != ERROR_OK) {
LOG_ERROR("Failed to execute algorithm at 0x%" TARGET_PRIxADDR ": %d",
algorithm_wa->address, retval);
return retval;
goto exit;
}
}
return ERROR_OK;
exit:
destroy_reg_param(&reg_params[1]);
destroy_reg_param(&reg_params[0]);
return retval;
}
static int fespi_write(struct flash_bank *bank, const uint8_t *buffer,