From: Michael Sweet Date: Wed, 30 Aug 2017 00:42:05 +0000 (-0400) Subject: `httpAddrConnect` leaked sockets in certain circumstances, causing some X-Git-Tag: v2.2.5~34 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7b0a28e38f20050bb2fce53d48d3e88f2d0d6d3e;p=thirdparty%2Fcups.git `httpAddrConnect` leaked sockets in certain circumstances, causing some printers to hang (rdar://31965686) --- diff --git a/CHANGES.md b/CHANGES.md index d2bbe5b278..95a42bfeea 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -37,6 +37,8 @@ CHANGES IN CUPS V2.2.5 choosing them for draft, normal, and best quality modes (Issue #5091) - Fixed the localization unit test on Linux (Issue #5097) - The CUPS library did not reuse domain sockets (Issue #5098) +- `httpAddrConnect` leaked sockets in certain circumstances, causing some + printers to hang (rdar://31965686) - Fixed an issue with Chinese localizations on macOS (rdar://32419311) - The IPP backend now always sends the "finishings" attribute for printers that support it because otherwise the client cannot override printer defaults diff --git a/cups/http-addrlist.c b/cups/http-addrlist.c index 22bd5a7d7f..e5fc940e1b 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 */