Skip to contentSkip to conversation

tools: Fix handle leak in mmap_fdt function

PATCH In review Maks Mishin 2 participants 2 messages Feb 9, 2025 – Feb 18, 2025

lore
Share & tools
lore
#0 lore raw

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.

---
 tools/fit_common.c | 1 +
 1 file changed, 1 insertion(+)
tools/fit_common.c +1 -0
index d1cde16c1c..135e105929 100644
@@ -123,6 +123,7 @@ err:
 		close(fd);
 	if (delete_on_error)
 		unlink(fname);
+	free(ptr);
 
 	return -1;
 }
Signature · 1 line
2.34.1
#1 lore raw
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 for ptr if ptr != MAP_FAILED.

Trigger was found by the Svace static analyzer.

---
 tools/fit_common.c | 1 +
 1 file changed, 1 insertion(+)
tools/fit_common.c +0 -0
index d1cde16c1c..135e105929 100644

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