Blame SOURCES/0003-libndp-close-sockfd-after-using-to-avoid-handle-leak.patch

f9401c
From 81df977dc0c2a04d5fa0c18dee130490d84a92f5 Mon Sep 17 00:00:00 2001
f9401c
From: Hangbin Liu <haliu@redhat.com>
f9401c
Date: Thu, 20 Dec 2018 11:48:16 +0800
f9401c
Subject: [PATCH 03/04] libndp: close sockfd after using to avoid handle leak
f9401c
f9401c
Fixes: acccd780df517 ("ndptool: add -T target support")
f9401c
Signed-off-by: Hangbin Liu <haliu@redhat.com>
f9401c
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
f9401c
---
f9401c
 libndp/libndp.c | 12 ++++++++----
f9401c
 1 file changed, 8 insertions(+), 4 deletions(-)
f9401c
f9401c
diff --git a/libndp/libndp.c b/libndp/libndp.c
f9401c
index bec55d4..f327d45 100644
f9401c
--- a/libndp/libndp.c
f9401c
+++ b/libndp/libndp.c
f9401c
@@ -736,7 +736,7 @@ void ndp_msg_target_set(struct ndp_msg *msg, struct in6_addr *target)
f9401c
 
f9401c
 static int ndp_get_iface_mac(int ifindex, char *ptr)
f9401c
 {
f9401c
-	int sockfd;
f9401c
+	int sockfd, err = 0;
f9401c
 	struct ifreq ifr;
f9401c
 
f9401c
 	sockfd = socket(AF_INET, SOCK_DGRAM, 0);
f9401c
@@ -747,17 +747,21 @@ static int ndp_get_iface_mac(int ifindex, char *ptr)
f9401c
 
f9401c
 	if (if_indextoname(ifindex, (char *)&ifr.ifr_name) == NULL) {
f9401c
 		pr_err("%s: Failed to get iface name with index %d", __func__, ifindex);
f9401c
-		return -errno;
f9401c
+		err = -errno;
f9401c
+		goto close_sock;
f9401c
 	}
f9401c
 
f9401c
 	if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) {
f9401c
 		pr_err("%s: Failed to get iface mac with index %d\n", __func__, ifindex);
f9401c
-		return -errno;
f9401c
+		err = -errno;
f9401c
+		goto close_sock;
f9401c
 	}
f9401c
 
f9401c
 	memcpy(ptr, &ifr.ifr_hwaddr.sa_data, sizeof(ifr.ifr_hwaddr.sa_data));
f9401c
 
f9401c
-	return 0;
f9401c
+close_sock:
f9401c
+	close(sockfd);
f9401c
+	return err;
f9401c
 }
f9401c
 
f9401c
 static void ndp_msg_opt_set_linkaddr(struct ndp_msg *msg, int ndp_opt)
f9401c
-- 
f9401c
2.19.2
f9401c