tools: Fix handle leak in mmap_fdt function
PATCH 1/1 tools: Fix handle leak in mmap_fdt function
The handle 'ptr' is created at fit_common.c:91 by calling function 'mmap' and lost at fit_common.c:127:
Added call of free for ptr if ptr != MAP_FAILED.
Trigger was found by the Svace static analyzer.
Signed-off-by Maks Mishin <[email protected]>
--- tools/fit_common.c | 1 + 1 file changed, 1 insertion(+)
tools/fit_common.c +1 -0
@@ -123,6 +123,7 @@ err:close (fd);if (delete_on_error)unlink (fname); +free (ptr);return -1 ; }
Signature · 1 line
2.34.1
Quoted 16 lines · Maks Mishin
The handle 'ptr' is created at fit_common.c:91 by calling function 'mmap' and lost at fit_common.c:127:
Added call of free forptrif ptr !=MAP_FAILED.Trigger was found by the Svace static analyzer.
Signed-off-by Maks Mishin <[email protected]>--- tools/fit_common.c | 1 + 1 file changed, 1 insertion(+)tools/fit_common.c +0
-0
tools/fit_common.c err: · line 129
Quoted 7 lines
tools/fit_common.c +1
-0@@ -123,6 +123,7 @@ err:close (fd);if (delete_on_error)unlink (fname); +free (ptr);return -1 ; }
This introduces:/home/uboot/u-boot/u-boot/tools/fit_common.c: In function 'mmap_fdt':/home/uboot/u-boot/u-boot/tools/fit_common.c:126:9: warning: 'ptr' may be used uninitialized in
this function [-Wmaybe-uninitialized]
126 | free(ptr);
| ^~~~~~~~~Signature · 1 line
Tom