mirror of
https://github.com/curl/curl.git
synced 2025-02-23 15:10:03 +08:00
clean up the dir tree hierarchy in *_done() to make persistant connection
FTP use the correct directories! Reported in bug report #783116
This commit is contained in:
parent
b9fdf3cc3b
commit
1e7e53c87e
53
lib/ftp.c
53
lib/ftp.c
@ -105,6 +105,15 @@ static CURLcode ftp_cwd(struct connectdata *conn, char *path);
|
|||||||
/* easy-to-use macro: */
|
/* easy-to-use macro: */
|
||||||
#define FTPSENDF(x,y,z) if((result = Curl_ftpsendf(x,y,z))) return result
|
#define FTPSENDF(x,y,z) if((result = Curl_ftpsendf(x,y,z))) return result
|
||||||
|
|
||||||
|
static void freedirs(struct FTP *ftp)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i=0; ftp->dirs[i]; i++){
|
||||||
|
free(ftp->dirs[i]);
|
||||||
|
ftp->dirs[i]=NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
* AllowServerConnect()
|
* AllowServerConnect()
|
||||||
@ -598,6 +607,14 @@ CURLcode Curl_ftp_done(struct connectdata *conn)
|
|||||||
int ftpcode;
|
int ftpcode;
|
||||||
CURLcode result=CURLE_OK;
|
CURLcode result=CURLE_OK;
|
||||||
|
|
||||||
|
/* free the dir tree parts */
|
||||||
|
freedirs(ftp);
|
||||||
|
|
||||||
|
if(ftp->file) {
|
||||||
|
free(ftp->file);
|
||||||
|
ftp->file = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if(data->set.upload) {
|
if(data->set.upload) {
|
||||||
if((-1 != data->set.infilesize) &&
|
if((-1 != data->set.infilesize) &&
|
||||||
(data->set.infilesize != *ftp->bytecountp) &&
|
(data->set.infilesize != *ftp->bytecountp) &&
|
||||||
@ -2161,7 +2178,8 @@ CURLcode Curl_ftp(struct connectdata *conn)
|
|||||||
|
|
||||||
if (!ftp->dirs[path_part]) { /* run out of memory ... */
|
if (!ftp->dirs[path_part]) { /* run out of memory ... */
|
||||||
failf(data, "no memory");
|
failf(data, "no memory");
|
||||||
retcode = CURLE_OUT_OF_MEMORY;
|
freedirs(ftp);
|
||||||
|
return CURLE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -2175,17 +2193,10 @@ CURLcode Curl_ftp(struct connectdata *conn)
|
|||||||
/* too deep, we need the last entry to be kept NULL at all
|
/* too deep, we need the last entry to be kept NULL at all
|
||||||
times to signal end of list */
|
times to signal end of list */
|
||||||
failf(data, "too deep dir hierarchy");
|
failf(data, "too deep dir hierarchy");
|
||||||
retcode = CURLE_URL_MALFORMAT;
|
freedirs(ftp);
|
||||||
|
return CURLE_URL_MALFORMAT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (retcode) {
|
|
||||||
int i;
|
|
||||||
for (i=0;i<path_part;i++) { /* free previous parts */
|
|
||||||
free(ftp->dirs[i]);
|
|
||||||
ftp->dirs[i]=NULL;
|
|
||||||
}
|
|
||||||
return retcode; /* failure */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ftp->file = cur_pos; /* the rest is the file name */
|
ftp->file = cur_pos; /* the rest is the file name */
|
||||||
@ -2193,11 +2204,7 @@ CURLcode Curl_ftp(struct connectdata *conn)
|
|||||||
if(*ftp->file) {
|
if(*ftp->file) {
|
||||||
ftp->file = curl_unescape(ftp->file, 0);
|
ftp->file = curl_unescape(ftp->file, 0);
|
||||||
if(NULL == ftp->file) {
|
if(NULL == ftp->file) {
|
||||||
int i;
|
freedirs(ftp);
|
||||||
for (i=0;i<path_part;i++){
|
|
||||||
free(ftp->dirs[i]);
|
|
||||||
ftp->dirs[i]=NULL;
|
|
||||||
}
|
|
||||||
failf(data, "no memory");
|
failf(data, "no memory");
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
@ -2288,22 +2295,20 @@ CURLcode Curl_ftpsendf(struct connectdata *conn,
|
|||||||
CURLcode Curl_ftp_disconnect(struct connectdata *conn)
|
CURLcode Curl_ftp_disconnect(struct connectdata *conn)
|
||||||
{
|
{
|
||||||
struct FTP *ftp= conn->proto.ftp;
|
struct FTP *ftp= conn->proto.ftp;
|
||||||
int i;
|
|
||||||
|
|
||||||
/* The FTP session may or may not have been allocated/setup at this point! */
|
/* The FTP session may or may not have been allocated/setup at this point! */
|
||||||
if(ftp) {
|
if(ftp) {
|
||||||
if(ftp->entrypath)
|
if(ftp->entrypath)
|
||||||
free(ftp->entrypath);
|
free(ftp->entrypath);
|
||||||
if(ftp->cache)
|
if(ftp->cache) {
|
||||||
free(ftp->cache);
|
free(ftp->cache);
|
||||||
if(ftp->file)
|
ftp->cache = NULL;
|
||||||
free(ftp->file);
|
|
||||||
for (i=0;ftp->dirs[i];i++){
|
|
||||||
free(ftp->dirs[i]);
|
|
||||||
ftp->dirs[i]=NULL;
|
|
||||||
}
|
}
|
||||||
|
if(ftp->file) {
|
||||||
ftp->file = NULL; /* zero */
|
free(ftp->file);
|
||||||
|
ftp->file = NULL; /* zero */
|
||||||
|
}
|
||||||
|
freedirs(ftp);
|
||||||
}
|
}
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user