Steve Holme wrote:
> Looking at the code the only problem I can see is in singleipconnect() when
> the default clause gets called in "switch (error)".

This indeed looks wrong, though I fail to provoke the socket leak on any of my 
machines.

My attempts at getting access to a sparc machine are still unsuccessful, so I'm 
submitting this patch untested on sparc. It doesn't feel terribly good doing 
debugging via the autobuilders, but on the other hand it doesn't feel good 
leaving the issue unattended either.

-- 
Björn
From f08edd0fae0f00475c915113893bc355dbe1b9f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Stenberg?= <bj...@haxx.se>
Date: Tue, 12 Nov 2013 21:09:03 +0100
Subject: [PATCH] connect: Return the socket descriptor even on fail

singleipconnect() did not return the open socket descriptor on some
errors, thereby sometimes causing a socket leak.
This patch ensures the socket is always returned.
---
 lib/connect.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/connect.c b/lib/connect.c
index 67f7334..e4d4fee 100644
--- a/lib/connect.c
+++ b/lib/connect.c
@@ -1027,6 +1027,8 @@ singleipconnect(struct connectdata *conn,
   conn->bits.ipv6 = (addr.family == AF_INET6)?TRUE:FALSE;
 #endif
 
+  *sockp = sockfd;
+
   if(-1 == rc) {
     switch (error) {
     case EINPROGRESS:
@@ -1040,7 +1042,6 @@ singleipconnect(struct connectdata *conn,
     case EAGAIN:
 #endif
 #endif
-      *sockp = sockfd;
       return CURLE_OK;
 
     default:
@@ -1053,8 +1054,6 @@ singleipconnect(struct connectdata *conn,
       return CURLE_COULDNT_CONNECT;
     }
   }
-  else
-    *sockp = sockfd;
 
   return CURLE_OK;
 }
-- 
1.8.4.rc3

Attachment: signature.asc
Description: Digital signature

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to