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 <[email protected]>
---
 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

Reply via email to