The opts.remaining_header string is alocated before the netlink callback object is created. But the callback object allocation can fail and the function will return in this case. To fix this, either the string buffer must be freed in this case or the opts.remaining_header allocation can simply be moved to a later point.
Fixes: 0a14f8800dac ("batctl: Handle nl_cb_alloc errors") Signed-off-by: Sven Eckelmann <s...@narfation.org> --- routing_algo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routing_algo.c b/routing_algo.c index 5aa4597..c3f4580 100644 --- a/routing_algo.c +++ b/routing_algo.c @@ -95,12 +95,12 @@ static int print_routing_algos(struct state *state) nl_send_auto_complete(state->sock, msg); nlmsg_free(msg); - opts.remaining_header = strdup("Available routing algorithms:\n"); - cb = nl_cb_alloc(NL_CB_DEFAULT); if (!cb) return -ENOMEM; + opts.remaining_header = strdup("Available routing algorithms:\n"); + nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, netlink_print_common_cb, &opts); nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, netlink_stop_callback, NULL); -- 2.47.2