[PATCH] tools: image-host: Fix potential memory leaks
Maks Mishin
maks.mishinfz at gmail.com
Mon Feb 3 17:10:12 CET 2025
For a variable `info.name` memory is allocated when calling the
`fit_image_setup_sig` function and is lost when the error code is returned.
The situation is similar for the `region_prop` variable,
the memory for which is allocated by calling the function `fit_config_get_regions`.
Signed-off-by: Maks Mishin <maks.mishinFZ at gmail.com>
---
tools/image-host.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/tools/image-host.c b/tools/image-host.c
index 84095d760c..8d1f6b209e 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -237,10 +237,13 @@ static int fit_image_process_sig(const char *keydir, const char *keyfile,
uint value_len;
int ret;
- if (fit_image_setup_sig(&info, keydir, keyfile, fit, image_name,
+ ret = fit_image_setup_sig(&info, keydir, keyfile, fit, image_name,
noffset, require_keys ? "image" : NULL,
- engine_id, algo_name))
+ engine_id, algo_name);
+ if (ret) {
+ free(info.name);
return -1;
+ }
node_name = fit_get_name(fit, noffset, NULL);
region.data = data;
@@ -1058,15 +1061,22 @@ static int fit_config_process_sig(const char *keydir, const char *keyfile,
int ret;
node_name = fit_get_name(fit, noffset, NULL);
- if (fit_config_get_regions(fit, conf_noffset, noffset, ®ion,
+ ret = fit_config_get_regions(fit, conf_noffset, noffset, ®ion,
®ion_count, ®ion_prop,
- ®ion_proplen))
+ ®ion_proplen);
+ if (ret) {
+ free(region_prop);
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(region_prop);
+ free(info.name);
return -1;
+ }
ret = info.crypto->sign(&info, region, region_count, &value,
&value_len);
--
2.34.1
More information about the U-Boot
mailing list