From d5b5f64bce3a86ae39361248da6b3b207cff2cd2 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 5 Dec 2011 12:34:27 +0100 Subject: 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 --- lib/connect.c | 12 ++++++++---- lib/ftp.c | 1 + lib/urldata.h | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/connect.c b/lib/connect.c index 445261754..a560c4d3b 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 38a5f10c9..b64ef6265 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 55f0a7b85..53df18cab 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]; -- cgit v1.2.3