1
0
Fork 0
mirror of https://gitlab.postmarketos.org/postmarketOS/pmaports.git synced 2025-07-12 16:19:48 +03:00
pmaports/main/dtbtool-exynos/0009-dtbtool-exynos-free-allocated-dtb_files-before-exit.patch
Henrik Grimler 481e494cdc
main/dtbtool-exynos: fix unreliable behaviour
Hopefully these can be merged in the repo we track, but let's add them
to pmaports in the meanwhile.

Fixes issue where allocated, but non-set memory is used, which gives
unpredictable behaviour.

Part-of: https://gitlab.postmarketos.org/postmarketOS/pmaports/-/merge_requests/6746
[ci:skip-build]: already built successfully in CI
2025-07-11 22:03:33 +02:00

73 lines
1.7 KiB
Diff

From 4917606a69a5134863ac27b3b590d323355f9cfb Mon Sep 17 00:00:00 2001
From: Henrik Grimler <henrik@grimler.se>
Date: Mon, 30 Jun 2025 16:59:58 +0200
Subject: [PATCH] dtbtool-exynos: free allocated dtb_files before exit
Otherwise tools like valgrind detects memory leaks.
---
dtbtool-exynos.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/dtbtool-exynos.c b/dtbtool-exynos.c
index 2164aae18159..efb6baecc828 100644
--- a/dtbtool-exynos.c
+++ b/dtbtool-exynos.c
@@ -355,6 +355,14 @@ static void *load_dtbh_block(char **dtb_files, unsigned pagesize,
return dtbh;
}
+void free_dtb_files(char **dtb_files) {
+ if (!dtb_files) return;
+ for (int i = 0; dtb_files[i]; i++) {
+ free(dtb_files[i]);
+ }
+ free(dtb_files);
+}
+
static int usage(void)
{
fprintf(stderr, "usage: dtbtool\n"
@@ -415,28 +423,36 @@ int main(int argc, char **argv)
if (!dt_img) {
error("no output filename specified");
+ free_dtb_files(dtb_files);
usage();
}
- if (dt_count == 0)
+ if (dt_count == 0) {
+ free_dtb_files(dtb_files);
fail("no dtb files found");
+ }
dt_data = load_dtbh_block(dtb_files, pagesize, dt_platform_code, dt_subtype_code, &dt_size);
- if (!dt_data)
+ if (!dt_data) {
+ free_dtb_files(dtb_files);
fail("could not load device tree blobs");
+ }
fd = open(dt_img, O_CREAT | O_TRUNC | O_WRONLY, 0644);
- if (fd < 0)
+ if (fd < 0) {
+ free_dtb_files(dtb_files);
fail("could not create output file '%s': %s", dt_img, strerror(errno));
+ }
if (write(fd, dt_data, dt_size) != dt_size) {
unlink(dt_img);
close(fd);
+ free_dtb_files(dtb_files);
fail("failed writing '%s': %s", dt_img, strerror(errno));
}
+ free_dtb_files(dtb_files);
close(fd);
return 0;
-
}
--
2.50.0