[PATCH 28/28] batctl: bisect_iv: drop dangling phantom event on OOM error

Sven Eckelmann <[email protected]> Sun, 21 Jun 2026 16:24:18 +0200
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
When routing_table_new() fails to allocate rt_table->entries, it might
alrady have allocated the seqno_event for RT_FLAG_DELETE. This seqno_event
is also already part of the orig_event->event_list.

To avoid this dangling DELETE event, it must also be unlinked and freed.

Fixes: ece05e1c4c1f ("[batctl] bisect (a tool to analyze logfiles) added")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 bisect_iv.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/bisect_iv.c b/bisect_iv.c
index 6c3f5d6..43b97e4 100644
--- a/bisect_iv.c
+++ b/bisect_iv.c
@@ -187,8 +187,8 @@ static void node_free(void *data)
 
 static int routing_table_new(char *orig, char *next_hop, char *old_next_hop, char rt_flag)
 {
+	struct seqno_event *seqno_event = NULL;
 	struct rt_table *prev_rt_table = NULL;
-	struct seqno_event *seqno_event;
 	struct bat_node *next_hop_node;
 	struct orig_event *orig_event;
 	struct rt_table *rt_table;
@@ -334,6 +334,10 @@ static int routing_table_new(char *orig, char *next_hop, char *old_next_hop, cha
 	if (!rt_table->entries) {
 		fprintf(stderr,
 			"Could not allocate memory for routing table entries (out of mem?) - skipping");
+		if (rt_flag == RT_FLAG_DELETE && seqno_event) {
+			list_del(&seqno_event->list);
+			free(seqno_event);
+		}
 		goto rt_hist_free;
 	}
 

-- 
2.47.3