Commit d5b5f64b authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

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
parent 088ba97a
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -1110,9 +1110,13 @@ curl_socket_t Curl_getconnectinfo(struct SessionHandle *data,
int Curl_closesocket(struct connectdata *conn,
                     curl_socket_t sock)
{
  if(conn && conn->fclosesocket)
  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);
  else
  }
  return sclose(sock);
}

+1 −0
Original line number Diff line number Diff line
@@ -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() */
  }
+2 −1
Original line number Diff line number Diff line
@@ -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];

+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ moo
[CLOSE] counter: 2
moo
[CLOSE] counter: 1
[CLOSE] counter: 0
</datacheck>
</reply>