diff options
author | Hangbin Liu <haliu@redhat.com> | 2018-12-20 11:48:16 +0800 |
---|---|---|
committer | Jiri Pirko <jiri@mellanox.com> | 2019-01-07 12:14:10 +0100 |
commit | 81df977dc0c2a04d5fa0c18dee130490d84a92f5 (patch) | |
tree | 8397602d4fd3061ccca16ddb8baafbf538e576e8 | |
parent | e67999b18c59d37d59b557316dfe53ed5d52e923 (diff) | |
download | libndp-81df977dc0c2a04d5fa0c18dee130490d84a92f5.tar.gz |
libndp: close sockfd after using to avoid handle leak
Fixes: acccd780df517 ("ndptool: add -T target support")
Signed-off-by: Hangbin Liu <haliu@redhat.com>
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
-rw-r--r-- | libndp/libndp.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/libndp/libndp.c b/libndp/libndp.c index bec55d4..f327d45 100644 --- a/libndp/libndp.c +++ b/libndp/libndp.c @@ -736,7 +736,7 @@ void ndp_msg_target_set(struct ndp_msg *msg, struct in6_addr *target) static int ndp_get_iface_mac(int ifindex, char *ptr) { - int sockfd; + int sockfd, err = 0; struct ifreq ifr; sockfd = socket(AF_INET, SOCK_DGRAM, 0); @@ -747,17 +747,21 @@ static int ndp_get_iface_mac(int ifindex, char *ptr) if (if_indextoname(ifindex, (char *)&ifr.ifr_name) == NULL) { pr_err("%s: Failed to get iface name with index %d", __func__, ifindex); - return -errno; + err = -errno; + goto close_sock; } if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) { pr_err("%s: Failed to get iface mac with index %d\n", __func__, ifindex); - return -errno; + err = -errno; + goto close_sock; } memcpy(ptr, &ifr.ifr_hwaddr.sa_data, sizeof(ifr.ifr_hwaddr.sa_data)); - return 0; +close_sock: + close(sockfd); + return err; } static void ndp_msg_opt_set_linkaddr(struct ndp_msg *msg, int ndp_opt) |