[B.A.T.M.A.N.] [PATCH 08/10] batctl: Free nl_sock when if_nametoindex failed

Sven Eckelmann
2017-11-23T14:04:42Z

The if_nametoindex can return an error. The code must then free the
previously allocated nl_sock and stop the function with an error code.

Fixes: d8dd1ff1a0fe ("batctl: Use netlink to replace some of debugfs")
Signed-off-by: Sven Eckelmann <sven.eckelmann@openmesh.com>
---
netlink.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/netlink.c b/netlink.c
index de81d08..7b97809 100644
--- a/netlink.c
+++ b/netlink.c
@@ -1137,7 +1137,8 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface,
ifindex = if_nametoindex(mesh_iface);
if (!ifindex) {
fprintf(stderr, "Interface %s is unknown\n", mesh_iface);
- return -ENODEV;
+ last_err = -ENODEV;
+ goto err_free_sock;
}

if (orig_iface) {
@@ -1145,7 +1146,8 @@ static int netlink_print_common(char *mesh_iface, char *orig_iface,
if (!hardifindex) {
fprintf(stderr, "Interface %s is unknown\n",
orig_iface);
- return -ENODEV;
+ last_err = -ENODEV;
+ goto err_free_sock;
}
}

--
2.11.0