From: Daniel Stenberg Date: Mon, 5 Dec 2011 11:34:27 +0000 (+0100) Subject: FTP: close callback fix X-Git-Tag: curl-7_24_0~156 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d5b5f64bce3a8;p=thirdparty%2Fcurl.git FTP: close callback fix 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 --- diff --git a/lib/connect.c b/lib/connect.c index 4452617547..a560c4d3bb 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -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); } /* diff --git a/lib/ftp.c b/lib/ftp.c index 38a5f10c91..b64ef6265a 100644 --- 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() */ } diff --git a/lib/urldata.h b/lib/urldata.h index 55f0a7b851..53df18cab7 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -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]; diff --git a/tests/data/test596 b/tests/data/test596 index 73e8a78d58..bb5def43fe 100644 --- a/tests/data/test596 +++ b/tests/data/test596 @@ -19,7 +19,6 @@ moo [CLOSE] counter: 2 moo [CLOSE] counter: 1 -[CLOSE] counter: 0