dcavalca / rpms / linuxptp

Forked from rpms/linuxptp 2 years ago
Clone

Blame SOURCES/linuxptp-closesocket.patch

63489c
commit a3500e14ca4af38034d5ad2115ca7ac271c8c5b4
63489c
Author: Miroslav Lichvar <mlichvar@redhat.com>
63489c
Date:   Mon Feb 6 15:43:00 2017 +0100
63489c
63489c
    Fix leaks of sockets on errors.
63489c
    
63489c
    Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
63489c
63489c
diff --git a/clock.c b/clock.c
63489c
index a6a1a1a..9481606 100644
63489c
--- a/clock.c
63489c
+++ b/clock.c
63489c
@@ -824,11 +824,13 @@ static int clock_add_port(struct clock *c, int phc_index,
63489c
 	}
63489c
 	index = sk_interface_index(fd, iface->name);
63489c
 	if (index < 0) {
63489c
+		close(fd);
63489c
 		return -1;
63489c
 	}
63489c
 	snprintf(key, sizeof(key), "%d", index);
63489c
 	if (hash_insert(c->index2port, key, p)) {
63489c
 		pr_err("failed to add port with index %d twice!", index);
63489c
+		close(fd);
63489c
 		return -1;
63489c
 	}
63489c
 	close(fd);
63489c
diff --git a/rtnl.c b/rtnl.c
63489c
index 7f5dc45..251b5f3 100644
63489c
--- a/rtnl.c
63489c
+++ b/rtnl.c
63489c
@@ -160,6 +160,7 @@ int rtnl_open(void)
63489c
 	}
63489c
 	if (bind(fd, (struct sockaddr *) &sa, sizeof(sa))) {
63489c
 		pr_err("failed to bind netlink socket: %m");
63489c
+		close(fd);
63489c
 		return -1;
63489c
 	}
63489c
 	return fd;