If the common netlink helper or the routing algorithm code never printed
the header, nothing would clean up the remaining_headers. Explicitly free
it up to avoid a minor memory leak.

Fixes: 5401c71adfad ("batctl: Use debugfs fallback when netlink not supported")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 netlink.c      | 4 ++++
 routing_algo.c | 6 +++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/netlink.c b/netlink.c
index 9d3d3c6..1121956 100644
--- a/netlink.c
+++ b/netlink.c
@@ -589,6 +589,10 @@ int netlink_print_common(struct state *state, char 
*orig_iface, int read_opt,
 
        } while (!last_err && read_opt & (CONT_READ | CLR_CONT_READ));
 
+       /* free a header that was prepared but never printed (e.g. on error) */
+       free(opts.remaining_header);
+       opts.remaining_header = NULL;
+
        bat_hosts_free();
 
        return last_err;
diff --git a/routing_algo.c b/routing_algo.c
index c3f4580..1c2c2b4 100644
--- a/routing_algo.c
+++ b/routing_algo.c
@@ -108,8 +108,12 @@ static int print_routing_algos(struct state *state)
 
        nl_recvmsgs(state->sock, cb);
 
-       if (!last_err)
+       if (!last_err) {
                netlink_print_remaining_header(&opts);
+       } else {
+               free(opts.remaining_header);
+               opts.remaining_header = NULL;
+       }
 
        return last_err;
 }

-- 
2.47.3

Reply via email to