[PATCH 02/12] batctl: netlink: abort netlink_print_common when message allocation fails
Sven Eckelmann <[email protected]> Wed, 08 Jul 2026 22:00:08 +0200
| Newsgroups | org.open-mesh.lists.batman |
|---|---|
| Message-ID | <[email protected]> |
When nlmsg_alloc() fails, netlink_print_common() just continues. In
one-shot mode this leaves the loop with the stale last_err of 0 and the
command reports success even though nothing was queried or printed. In
watch mode the loop retries immediately without the usleep() pause and
leaks the header that netlink_get_info() prepared in the previous
iteration.
Treat the allocation failure as -ENOMEM and leave the query loop.
Fixes: d8dd1ff1a0fe ("batctl: Use netlink to replace some of debugfs")
Signed-off-by: Sven Eckelmann <[email protected]>
---
netlink.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/netlink.c b/netlink.c
index 4a3ab60..cb65655 100644
--- a/netlink.c
+++ b/netlink.c
@@ -567,8 +567,10 @@ int netlink_print_common(struct state *state, char *orig_iface, int read_opt,
header);
msg = nlmsg_alloc();
- if (!msg)
- continue;
+ if (!msg) {
+ last_err = -ENOMEM;
+ break;
+ }
genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, state->batadv_family,
0, NLM_F_DUMP, nl_cmd, 1);
--
2.47.3