Skip to contentSkip to conversation

tools: image-host: Fix potential memory leak

PATCH In review [email protected] 2 participants 2 messages Apr 18, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools: image-host: Fix potential memory leak

From: Maks Mishin <[email protected]>

---
 tools/image-host.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tools/image-host.c +5 -2
index 4a24dee8..453cd38f 100644
@@ -1029,10 +1029,13 @@ static int fit_config_process_sig(const char *keydir, const char *keyfile,
 				   &region_proplen))
 		return -1;
 
-	if (fit_image_setup_sig(&info, keydir, keyfile, fit, conf_name, noffset,
+	ret = fit_image_setup_sig(&info, keydir, keyfile, fit, conf_name, noffset,
 				require_keys ? "conf" : NULL, engine_id,
-				algo_name))
+				algo_name);
+	if (ret) {
+		free(info.name);
 		return -1;
+	}
 
 	ret = info.crypto->sign(&info, region, region_count, &value,
 				&value_len);
Signature · 1 line
2.34.1
#1 lore raw

Hi,

Quoted 12 lines · On 4/18/25 10:30 AM, [email protected] wrote:

From: Maks Mishin <[email protected]>

---
  tools/image-host.c | 7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
tools/image-host.c +0 -0
index 4a24dee8..453cd38f 100644

tools/image-host.c static int fit_config_process_sig(const char *keydir, const char *keyfile, · line 1036

Quoted 10 lines
tools/image-host.c +4 -2
@@ -1029,10 +1029,13 @@ static int fit_config_process_sig(const char *keydir, const char *keyfile,
  				   &region_proplen))
  		return -1;
 
-	if (fit_image_setup_sig(&info, keydir, keyfile, fit, conf_name, noffset,
+	ret = fit_image_setup_sig(&info, keydir, keyfile, fit, conf_name, noffset,
  				require_keys ? "conf" : NULL, engine_id,
-				algo_name))
+				algo_name);
+	if (ret) {
+		free(info.name);

Don't we need to free it all the time (i mean in the happy path even, after it's not useful anymore?)? When is it not useful anymore?

Please provide some information in the commit log as well, thanks!

Cheers,
Quentin