[PATCH xtables-addons v2 08/13] pknock: pknlusr: always close socket.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On some error paths the socket was not being closed before exit.

Signed-off-by: Jeremy Sowden <jeremy@xxxxxxxxxx>
---
 extensions/pknock/pknlusr.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/extensions/pknock/pknlusr.c b/extensions/pknock/pknlusr.c
index 2dd9ab7b9705..fba628e1f466 100644
--- a/extensions/pknock/pknlusr.c
+++ b/extensions/pknock/pknlusr.c
@@ -29,7 +29,7 @@ int main(void)
 
 	if (sock_fd == -1) {
 		perror("socket()");
-		return 1;
+		exit (EXIT_FAILURE);
 	}
 
 	local_addr.nl_groups = group;
@@ -37,9 +37,8 @@ int main(void)
 	status = bind(sock_fd, (struct sockaddr*)&local_addr, sizeof(local_addr));
 
 	if (status == -1) {
-		close(sock_fd);
 		perror("bind()");
-		return 1;
+		goto err_close_sock;
 	}
 
 	nlmsg_size = NLMSG_SPACE(sizeof(*cn_msg) + sizeof(*pknock_msg));
@@ -47,7 +46,7 @@ int main(void)
 
 	if (!nlmsg) {
 		perror("malloc()");
-		return 1;
+		goto err_close_sock;
 	}
 
 	while(1) {
@@ -61,7 +60,7 @@ int main(void)
 
 		if (status < 0) {
 			perror("recv()");
-			return 1;
+			goto err_free_msg;
 		}
 
 		if (status == 0)
@@ -74,9 +73,11 @@ int main(void)
 
 	}
 
-	close(sock_fd);
-
+err_free_msg:
 	free(nlmsg);
 
-	return 0;
+err_close_sock:
+	close(sock_fd);
+
+	exit (status == -1 ? EXIT_FAILURE : EXIT_SUCCESS);
 }
-- 
2.28.0




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux