This is an automated email from Gerrit.

"Antonio Borneo <[email protected]>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/9163

-- gerrit

commit c776342959f4462204ab46bf3e6011fce8193a00
Author: Antonio Borneo <[email protected]>
Date:   Tue Oct 7 12:06:54 2025 +0200

    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 <[email protected]>

diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c
index 895550f0ab..4c801b2ddb 100644
--- a/src/target/riscv/riscv.c
+++ b/src/target/riscv/riscv.c
@@ -4221,9 +4221,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;
        }
 
@@ -4268,6 +4274,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.");

-- 

Reply via email to