This is an automated email from Gerrit.

"Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>" just uploaded a new patch 
set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7935

-- gerrit

commit 228ce4ad4859123b760a47c0b32c7cd6cd10b0c6
Author: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>
Date:   Tue Oct 10 13:57:43 2023 +0300

    target: fix a memory leak in image_open
    
    Change-Id: I629be26e7752858091ad58c2b3b07f43e22e8c23
    Signed-off-by: Evgeniy Naydanov <evgeniy.nayda...@syntacore.com>

diff --git a/src/target/image.c b/src/target/image.c
index e998a35f4d..0db0d6294a 100644
--- a/src/target/image.c
+++ b/src/target/image.c
@@ -967,12 +967,17 @@ int image_open(struct image *image, const char *url, 
const char *type_string)
                image_binary = image->type_private = malloc(sizeof(struct 
image_binary));
 
                retval = fileio_open(&image_binary->fileio, url, FILEIO_READ, 
FILEIO_BINARY);
-               if (retval != ERROR_OK)
+               if (retval != ERROR_OK) {
+                       free(image->type_private);
+                       image->type_private = NULL;
                        return retval;
+               }
                size_t filesize;
                retval = fileio_size(image_binary->fileio, &filesize);
                if (retval != ERROR_OK) {
                        fileio_close(image_binary->fileio);
+                       free(image->type_private);
+                       image->type_private = NULL;
                        return retval;
                }
 

-- 

Reply via email to