From b7a93248979b0a631ab95233f8a75de069e5e9ee Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sun, 20 Nov 2016 16:19:18 -0800 Subject: [PATCH] Minor resource and error logic cleanup in tunnel_socket_open() Free the conn->sockdata on failure. conn->fd is not set until the bottom, and before it is set, conn->conn_close() will not be called. Close the pin pipe if the pout pipe fails. Call mutt_perror first on a fork failure. Calling after the close() may cause errno to be changed on a close failure. --- mutt_tunnel.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mutt_tunnel.c b/mutt_tunnel.c index d49626e6..e199e07b 100644 --- a/mutt_tunnel.c +++ b/mutt_tunnel.c @@ -75,11 +75,15 @@ static int tunnel_socket_open (CONNECTION *conn) if ((rc = pipe (pin)) == -1) { mutt_perror ("pipe"); + FREE (&conn->sockdata); return -1; } if ((rc = pipe (pout)) == -1) { mutt_perror ("pipe"); + close (pin[0]); + close (pin[1]); + FREE (&conn->sockdata); return -1; } @@ -109,11 +113,12 @@ static int tunnel_socket_open (CONNECTION *conn) if (pid == -1) { + mutt_perror ("fork"); close (pin[0]); close (pin[1]); close (pout[0]); close (pout[1]); - mutt_perror ("fork"); + FREE (&conn->sockdata); return -1; } if (close (pin[1]) < 0 || close (pout[0]) < 0) -- 2.40.0