]> granicus.if.org Git - curl/commitdiff
FTP: close callback fix
authorDaniel Stenberg <daniel@haxx.se>
Mon, 5 Dec 2011 11:34:27 +0000 (12:34 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 5 Dec 2011 11:34:27 +0000 (12:34 +0100)
Keep track of which sockets that are the result of accept() calls and
refuse to call the closesocket callback for those sockets. Test case 596
now verifies that the open socket callback is called the same number of
times as the closed socket callback for active FTP connections.

Bug: http://curl.haxx.se/mail/lib-2011-12/0018.html
Reported by: Gokhan Sengun

lib/connect.c
lib/ftp.c
lib/urldata.h
tests/data/test596

index 44526175478d3acb3fdddb107876f81d26fe957f..a560c4d3bbf9bb97bb8800414a4b86201d805d9c 100644 (file)
@@ -1110,10 +1110,14 @@ curl_socket_t Curl_getconnectinfo(struct SessionHandle *data,
 int Curl_closesocket(struct connectdata *conn,
                      curl_socket_t sock)
 {
-  if(conn && conn->fclosesocket)
-    return conn->fclosesocket(conn->closesocket_client, sock);
-  else
-    return sclose(sock);
+  if(conn && conn->fclosesocket) {
+    if((sock != conn->sock[SECONDARYSOCKET]) ||
+       !conn->sock_accepted[SECONDARYSOCKET])
+      /* if this socket matches the second socket, and that was created with
+         accept, then we MUST NOT call the callback */
+      return conn->fclosesocket(conn->closesocket_client, sock);
+  }
+  return sclose(sock);
 }
 
 /*
index 38a5f10c91dc53ff3e9fb86c45660fb298869950..b64ef6265a8478518f4a4ba027fcbec661b348f5 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -368,6 +368,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
 
       conn->sock[SECONDARYSOCKET] = s;
       curlx_nonblock(s, TRUE); /* enable non-blocking */
+      conn->sock_accepted[SECONDARYSOCKET] = TRUE;
       return CURLE_OK;
     } /* switch() */
   }
index 55f0a7b851ae5d41aeb3cfa92671c7e4f50acf76..53df18cab73b3eea2f0855f200975f2a6e740e24 100644 (file)
@@ -816,7 +816,8 @@ struct connectdata {
   struct timeval created; /* creation time */
   curl_socket_t sock[2]; /* two sockets, the second is used for the data
                             transfer when doing FTP */
-
+  bool sock_accepted[2]; /* TRUE if the socket on this index was created with
+                            accept() */
   Curl_recv *recv[2];
   Curl_send *send[2];
 
index 73e8a78d589e2c160dc2578d2c62d9c23b096f77..bb5def43fed04a88d255150dcce905482bbe017d 100644 (file)
@@ -19,7 +19,6 @@ moo
 [CLOSE] counter: 2
 moo
 [CLOSE] counter: 1
-[CLOSE] counter: 0
 </datacheck>
 </reply>