[PATCH 1/6] alfred: keep interface names always in heap

Sven Eckelmann <[email protected]> Thu, 30 Jul 2026 21:31:55 +0200
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
The interface pointer in globals was used to store an address in .rodata or
in on the heap. This makes the handling of the allocation/deallocation
hard. At the same time, nothing checked for allocations problems. An
allocation error could cause an hard-to-debug problem later when trying to
calculate the ifindex.

Adjust the code to always allocate the string as an heap object to simplify
the handling.

Signed-off-by: Sven Eckelmann <[email protected]>
---
 main.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/main.c b/main.c
index 9c38fd7..21def01 100644
--- a/main.c
+++ b/main.c
@@ -191,7 +191,6 @@ static struct globals *alfred_init(int argc, char *argv[])
 	globals->clientmode = CLIENT_NONE;
 	globals->best_server = NULL;
 	globals->clientmode_version = 0;
-	globals->mesh_iface = "bat0";
 	globals->unix_path = ALFRED_SOCK_PATH_DEFAULT;
 	globals->verbose = false;
 	globals->ipv4mode = false;
@@ -201,6 +200,12 @@ static struct globals *alfred_init(int argc, char *argv[])
 	globals->sync_period.tv_nsec = 0;
 	bitmap_zero(globals->changed_data_types, ALFRED_NUM_TYPES);
 
+	globals->mesh_iface = strdup("bat0");
+	if (!globals->mesh_iface) {
+		perror("strdup");
+		return NULL;
+	}
+
 	time_random_seed();
 
 	while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:B:SEu:dc:p:4:f", long_options,

-- 
2.47.3