[08/10] batctl: Free nl_sock when if_nametoindex failed

Message ID 20171123140444.17119-9-sven.eckelmann@openmesh.com (mailing list archive)
State Accepted, archived
Commit 4361841bf76ecd27dcfca6edc30c63b05854d415
Delegated to: Simon Wunderlich
Headers
Series batctl: Fixes and minor cleanup |

Commit Message

Sven Eckelmann Nov. 23, 2017, 2:04 p.m. UTC
  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(-)
  

Patch

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;
 		}
 	}