diff options
author | Michael Sweet <michael.r.sweet@gmail.com> | 2017-08-29 20:42:05 -0400 |
---|---|---|
committer | Michael Sweet <michael.r.sweet@gmail.com> | 2017-08-29 20:42:05 -0400 |
commit | 7b0a28e38f20050bb2fce53d48d3e88f2d0d6d3e (patch) | |
tree | b18b63839f9b8c3164d7e30104872a372feabc37 /cups/http-addrlist.c | |
parent | e78c14f7ea27d1468a7d21eb1d688669a5ec3c43 (diff) | |
download | cups-7b0a28e38f20050bb2fce53d48d3e88f2d0d6d3e.tar.gz |
`httpAddrConnect` leaked sockets in certain circumstances, causing some
printers to hang (rdar://31965686)
Diffstat (limited to 'cups/http-addrlist.c')
-rw-r--r-- | cups/http-addrlist.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/cups/http-addrlist.c b/cups/http-addrlist.c index 22bd5a7d7..e5fc940e1 100644 --- a/cups/http-addrlist.c +++ b/cups/http-addrlist.c @@ -65,7 +65,7 @@ httpAddrConnect2( int flags; /* Socket flags */ #endif /* !WIN32 */ int remaining; /* Remaining timeout */ - int i, /* Looping var */ + int i, j, /* Looping vars */ nfds, /* Number of file descriptors */ fds[100], /* Socket file descriptors */ result; /* Result from select() or poll() */ @@ -323,6 +323,8 @@ httpAddrConnect2( if (!getpeername(fds[i], (struct sockaddr *)&peer, &len)) DEBUG_printf(("1httpAddrConnect2: Connected to %s:%d...", httpAddrString(&peer, temp, sizeof(temp)), httpAddrPort(&peer))); # endif /* DEBUG */ + + break; } # ifdef HAVE_POLL else if (pfds[i].revents & (POLLERR | POLLHUP)) @@ -346,7 +348,20 @@ httpAddrConnect2( } if (connaddr) + { + /* + * Connected on one address, close all of the other sockets we have so + * far and return... + */ + + for (j = 0; j < i; j ++) + httpAddrClose(NULL, fds[j]); + + for (j ++; j < nfds; j ++) + httpAddrClose(NULL, fds[j]); + return (connaddr); + } } #endif /* O_NONBLOCK */ |