From 88c8d72a214864952b6d1c2347b6c3f5b7d69e84 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 11 Dec 2006 09:32:58 +0000 Subject: Alexey Simak found out that when doing FTP with the multi interface and something went wrong like it got a bad response code back from the server, libcurl would leak memory. Added test case 538 to verify the fix. I also noted that the connection would get cached in that case, which doesn't make sense since it cannot be re-use when the authentication has failed. I fixed that issue too at the same time, and also that the path would be "remembered" in vain for cases where the connection was about to get closed. --- lib/ftp.c | 41 ++++++++++++++++++++++------------------- lib/url.c | 7 ++----- 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'lib') diff --git a/lib/ftp.c b/lib/ftp.c index 4e4dd5346..7175c99a7 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -2965,6 +2965,28 @@ CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status) */ return CURLE_OK; + switch(status) { + case CURLE_BAD_DOWNLOAD_RESUME: + case CURLE_FTP_WEIRD_PASV_REPLY: + case CURLE_FTP_PORT_FAILED: + case CURLE_FTP_COULDNT_SET_BINARY: + case CURLE_FTP_COULDNT_RETR_FILE: + case CURLE_FTP_COULDNT_STOR_FILE: + case CURLE_FTP_ACCESS_DENIED: + /* the connection stays alive fine even though this happened */ + /* fall-through */ + case CURLE_OK: /* doesn't affect the control connection's status */ + ftpc->ctl_valid = was_ctl_valid; + break; + default: /* by default, an error means the control connection is + wedged and should not be used anymore */ + ftpc->ctl_valid = FALSE; + ftpc->cwdfail = TRUE; /* set this TRUE to prevent us to remember the + current path, as this connection is going */ + conn->bits.close = TRUE; /* marked for closure */ + break; + } + /* now store a copy of the directory we are in */ if(ftpc->prevpath) free(ftpc->prevpath); @@ -2990,25 +3012,6 @@ CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status) /* free the dir tree and file parts */ freedirs(conn); - switch(status) { - case CURLE_BAD_DOWNLOAD_RESUME: - case CURLE_FTP_WEIRD_PASV_REPLY: - case CURLE_FTP_PORT_FAILED: - case CURLE_FTP_COULDNT_SET_BINARY: - case CURLE_FTP_COULDNT_RETR_FILE: - case CURLE_FTP_COULDNT_STOR_FILE: - case CURLE_FTP_ACCESS_DENIED: - /* the connection stays alive fine even though this happened */ - /* fall-through */ - case CURLE_OK: /* doesn't affect the control connection's status */ - ftpc->ctl_valid = was_ctl_valid; - break; - default: /* by default, an error means the control connection is - wedged and should not be used anymore */ - ftpc->ctl_valid = FALSE; - break; - } - #ifdef HAVE_KRB4 Curl_sec_fflush_fd(conn, conn->sock[SECONDARYSOCKET]); #endif diff --git a/lib/url.c b/lib/url.c index a028857e8..9a3c68d0b 100644 --- a/lib/url.c +++ b/lib/url.c @@ -2171,10 +2171,7 @@ static void ConnectionDone(struct connectdata *conn) { conn->inuse = FALSE; - conn->data = NULL; - - if (conn->send_pipe == 0 && - conn->recv_pipe == 0) + if (!conn->send_pipe && !conn->recv_pipe) conn->is_in_pipeline = FALSE; } @@ -3071,7 +3068,7 @@ static CURLcode CreateConnection(struct SessionHandle *data, conn->port = port; conn->remote_port = (unsigned short)port; - conn->protocol |= PROT_FTP|PROT_CLOSEACTION; + conn->protocol |= PROT_FTP; if(data->change.proxy && *data->change.proxy && -- cgit v1.2.3