target: riscv: fix memory leak in riscv_openocd_step_impl()
The array 'wps_to_enable' is never freed. Scan build reports: src/target/riscv/riscv.c:4271:6: warning: Potential leak of memory pointed to by 'wps_to_enable' [unix.Malloc] Add the needed free(). While there, check if the allocation is successful. Change-Id: I00e7ade37a43a97dcc245113ad93c48784fce609 Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com> Reviewed-on: https://review.openocd.org/c/openocd/+/9163 Reviewed-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com> Reviewed-by: Tomas Vanek <vanekt@fbl.cz> Tested-by: jenkins
This commit is contained in:
committed by
Tomas Vanek
parent
ed9cf6d81d
commit
be083909b7
@@ -4210,9 +4210,15 @@ static int riscv_openocd_step_impl(struct target *target, bool current,
|
||||
|
||||
RISCV_INFO(r);
|
||||
bool *wps_to_enable = calloc(r->trigger_count, sizeof(*wps_to_enable));
|
||||
if (!wps_to_enable) {
|
||||
LOG_ERROR("Out of memory");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
if (disable_watchpoints(target, wps_to_enable) != ERROR_OK) {
|
||||
LOG_TARGET_ERROR(target, "Failed to temporarily disable "
|
||||
"watchpoints before single-step.");
|
||||
free(wps_to_enable);
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
||||
@@ -4257,6 +4263,8 @@ _exit:
|
||||
"after single-step.");
|
||||
}
|
||||
|
||||
free(wps_to_enable);
|
||||
|
||||
if (breakpoint && (riscv_add_breakpoint(target, breakpoint) != ERROR_OK)) {
|
||||
success = false;
|
||||
LOG_TARGET_ERROR(target, "Unable to restore the disabled breakpoint.");
|
||||
|
||||
Reference in New Issue
Block a user