From: Sven Eckelmann <sven@narfation.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Sven Eckelmann <sven@narfation.org>
Subject: [PATCH 01/12] batctl: handle netlink callback object on error
Date: Wed, 08 Jul 2026 22:00:07 +0200 [thread overview]
Message-ID: <20260708-bugfixes-netlink-v1-1-8ce03e37f17b@narfation.org> (raw)
In-Reply-To: <20260708-bugfixes-netlink-v1-0-8ce03e37f17b@narfation.org>
The libnl callback object is allocated and must be deallocated when it is
no longer used. This is especially important when an error happened.
Fixes: d8dd1ff1a0fe ("batctl: Use netlink to replace some of debugfs")
Fixes: f109b3473f86 ("batctl: introduce throughput meter support")
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
netlink.c | 6 +++++-
routing_algo.c | 1 +
throughputmeter.c | 10 +++++++++-
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/netlink.c b/netlink.c
index 46fb993..4a3ab60 100644
--- a/netlink.c
+++ b/netlink.c
@@ -489,11 +489,15 @@ char *netlink_get_info(struct state *state, uint8_t nl_cmd, const char *header)
nl_cb_err(cb, NL_CB_CUSTOM, netlink_print_error, NULL);
ret = nl_recvmsgs(state->sock, cb);
- if (ret < 0)
+ if (ret < 0) {
+ nl_cb_put(cb);
return opts.remaining_header;
+ }
nl_wait_for_ack(state->sock);
+ nl_cb_put(cb);
+
return opts.remaining_header;
}
diff --git a/routing_algo.c b/routing_algo.c
index 1c2c2b4..167bd22 100644
--- a/routing_algo.c
+++ b/routing_algo.c
@@ -107,6 +107,7 @@ static int print_routing_algos(struct state *state)
nl_cb_err(cb, NL_CB_CUSTOM, netlink_print_error, NULL);
nl_recvmsgs(state->sock, cb);
+ nl_cb_put(cb);
if (!last_err) {
netlink_print_remaining_header(&opts);
diff --git a/throughputmeter.c b/throughputmeter.c
index 98a9490..1690bda 100644
--- a/throughputmeter.c
+++ b/throughputmeter.c
@@ -158,13 +158,18 @@ static int tp_meter_start(struct state *state, struct ether_addr *dst_mac,
int err = 0;
cb = nl_cb_alloc(NL_CB_DEFAULT);
+ if (!cb)
+ return -ENOMEM;
+
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, tp_meter_cookie_callback,
cookie);
nl_cb_err(cb, NL_CB_CUSTOM, tpmeter_nl_print_error, cookie);
msg = nlmsg_alloc();
- if (!msg)
+ if (!msg) {
+ nl_cb_put(cb);
return -ENOMEM;
+ }
genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, state->batadv_family, 0,
0, BATADV_CMD_TP_METER, 1);
@@ -200,6 +205,9 @@ static int tp_recv_result(struct nl_sock *sock, struct tp_result *result)
int err = 0;
cb = nl_cb_alloc(NL_CB_DEFAULT);
+ if (!cb)
+ return -ENOMEM;
+
nl_cb_set(cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, tp_meter_result_callback,
result);
--
2.47.3
next prev parent reply other threads:[~2026-07-08 20:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 20:00 [PATCH 00/12] batctl: netlink bugfixes Sven Eckelmann
2026-07-08 20:00 ` Sven Eckelmann [this message]
2026-07-08 20:00 ` [PATCH 02/12] batctl: netlink: abort netlink_print_common when message allocation fails Sven Eckelmann
2026-07-08 20:00 ` [PATCH 03/12] batctl: netlink: don't format NULL extra_info in info_callback Sven Eckelmann
2026-07-08 20:00 ` [PATCH 04/12] batctl: netlink: report dump errors signalled in the NLMSG_DONE message Sven Eckelmann
2026-07-08 20:00 ` [PATCH 05/12] batctl: netlink: detect receive errors in netlink_print_common Sven Eckelmann
2026-07-08 20:00 ` [PATCH 06/12] batctl: netlink: report kernel errors when writing settings Sven Eckelmann
2026-07-08 20:00 ` [PATCH 07/12] batctl: netlink: report send errors in netlink_simple_request Sven Eckelmann
2026-07-08 20:00 ` [PATCH 08/12] batctl: netlink: detect receive errors in query_rtnl_link Sven Eckelmann
2026-07-08 20:00 ` [PATCH 09/12] batctl: netlink: detect receive errors in netlink_simple_request Sven Eckelmann
2026-07-08 20:00 ` [PATCH 10/12] batctl: netlink: detect receive errors in query_rtnl_link_single Sven Eckelmann
2026-07-08 20:00 ` [PATCH 11/12] batctl: netlink: report error on query_rtnl_link send failure Sven Eckelmann
2026-07-08 20:00 ` [PATCH 12/12] batctl: netlink: use kernel-style error codes for nl_recvmsgs Sven Eckelmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260708-bugfixes-netlink-v1-1-8ce03e37f17b@narfation.org \
--to=sven@narfation.org \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox