From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Sven Eckelmann Date: Thu, 23 Nov 2017 15:04:42 +0100 Message-Id: <20171123140444.17119-9-sven.eckelmann@openmesh.com> In-Reply-To: <20171123140444.17119-1-sven.eckelmann@openmesh.com> References: <20171123140444.17119-1-sven.eckelmann@openmesh.com> Subject: [B.A.T.M.A.N.] [PATCH 08/10] batctl: Free nl_sock when if_nametoindex failed List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: b.a.t.m.a.n@lists.open-mesh.org Cc: Sven Eckelmann 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 --- 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