From: Kevin McCarthy Date: Mon, 21 Nov 2016 00:19:18 +0000 (-0800) Subject: Minor resource and error logic cleanup in tunnel_socket_open() X-Git-Tag: mutt-1-8-rel~71 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b7a93248979b0a631ab95233f8a75de069e5e9ee;p=mutt 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. --- 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)