Fix file descriptor leak in http.c
Hrvoje Niksic <[email protected]> Sat, 14 May 2005 21:10:51 +0200
| Newsgroups | gmane.comp.web.wget.patches |
|---|---|
| Message-ID | <[email protected]> |
I accidentally discovered a file descriptor leak in http connections when a redirection is encountered and the server announces that it will close the connection. For example: $ wget -d www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com |& grep "Created socket" Created socket 3. Created socket 4. Created socket 4. Created socket 5. Created socket 5. Created socket 6. Created socket 6. Created socket 7. Created socket 7. Created socket 8. Created socket 8. Created socket 9. Created socket 9. Created socket 10. Created socket 10. Created socket 11. Created socket 11. Created socket 12. Created socket 12. Created socket 13. ... The attached patch fixes the problem: $ wget -d www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com www.amazon.com |& grep "Created socket" Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. Created socket 3. 2005-05-14 Hrvoje Niksic <[email protected]> * http.c (gethttp): Would forget to close the connection when keep_alive was not used. Index: src/http.c =================================================================== RCS file: /pack/anoncvs/wget/src/http.c,v retrieving revision 1.185 diff -u -r1.185 http.c --- src/http.c 2005/05/11 15:52:26 1.185 +++ src/http.c 2005/05/14 19:10:12 @@ -1625,13 +1625,10 @@ if (statcode == HTTP_STATUS_UNAUTHORIZED) { /* Authorization is required. */ - if (keep_alive) - { - if (skip_short_body (sock, contlen)) - CLOSE_FINISH (sock); - else - CLOSE_INVALIDATE (sock); - } + if (keep_alive && skip_short_body (sock, contlen)) + CLOSE_FINISH (sock); + else + CLOSE_INVALIDATE (sock); pconn.authorized = 0; if (!auth_finished && (user && passwd)) { @@ -1768,13 +1765,10 @@ _("Location: %s%s\n"), hs->newloc ? escnonprint_uri (hs->newloc) : _("unspecified"), hs->newloc ? _(" [following]") : ""); - if (keep_alive) - { - if (skip_short_body (sock, contlen)) - CLOSE_FINISH (sock); - else - CLOSE_INVALIDATE (sock); - } + if (keep_alive && skip_short_body (sock, contlen)) + CLOSE_FINISH (sock); + else + CLOSE_INVALIDATE (sock); xfree_null (type); return NEWLOCATION; }