[PATCH] tools: image-host: Fix potential memory leaks
Tom Rini
trini at konsulko.com
Tue Feb 11 00:28:16 CET 2025
On Mon, Feb 03, 2025 at 07:10:12PM +0300, Maks Mishin wrote:
> 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(-)
This introduces a failure to build:
/home/trini/work/u-boot/u-boot/tools/image-host.c: In function ‘fit_image_process_sig’:
/home/trini/work/u-boot/u-boot/tools/image-host.c:244:26: warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
244 | free(info.name);
| ~~~~^~~~~
In file included from /home/trini/work/u-boot/u-boot/include/compiler.h:24,
from <command-line>:
/usr/include/stdlib.h:687:25: note: expected ‘void *’ but argument is of type ‘const char *’
687 | extern void free (void *__ptr) __THROW;
| ~~~~~~^~~~~
/home/trini/work/u-boot/u-boot/tools/image-host.c: In function ‘fit_config_process_sig’:
/home/trini/work/u-boot/u-boot/tools/image-host.c:1087:26: warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
1087 | free(info.name);
| ~~~~^~~~~
/usr/include/stdlib.h:687:25: note: expected ‘void *’ but argument is of type ‘const char *’
687 | extern void free (void *__ptr) __THROW;
| ~~~~~~^~~~~
In function ‘fit_config_process_sig’,
inlined from ‘fit_config_add_verification_data’ at /home/trini/work/u-boot/u-boot/tools/image-host.c:1156:10,
inlined from ‘fit_add_verification_data’ at /home/trini/work/u-boot/u-boot/tools/image-host.c:1377:9:
/home/trini/work/u-boot/u-boot/tools/image-host.c:1078:17: warning: ‘region_prop’ may be used uninitialized [-Wmaybe-uninitialized]
1078 | free(region_prop);
| ^~~~~~~~~~~~~~~~~
/home/trini/work/u-boot/u-boot/tools/image-host.c: In function ‘fit_add_verification_data’:
/home/trini/work/u-boot/u-boot/tools/image-host.c:1066:15: note: ‘region_prop’ was declared here
1066 | char *region_prop;
| ^~~~~~~~~~~
--
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20250210/90e38ea9/attachment.sig>
More information about the U-Boot
mailing list