avoid an extra malloc

This commit is contained in:
Daniel Stenberg 2004-12-17 10:09:32 +00:00
parent ff54a74b4d
commit e3d342df96

View File

@ -778,19 +778,16 @@ CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status)
flen = ftp->file?strlen(ftp->file):0; /* file is "raw" already */ flen = ftp->file?strlen(ftp->file):0; /* file is "raw" already */
dlen = strlen(path)-flen; dlen = strlen(path)-flen;
if(dlen) { if(dlen) {
ftp->prevpath = malloc(dlen + 1); ftp->prevpath = path;
if(!ftp->prevpath) { if(flen)
free(path); /* if 'path' is not the whole string */
return CURLE_OUT_OF_MEMORY;
}
memcpy(ftp->prevpath, path, dlen);
ftp->prevpath[dlen]=0; /* terminate */ ftp->prevpath[dlen]=0; /* terminate */
infof(data, "Remembering we are in dir %s\n", ftp->prevpath); infof(data, "Remembering we are in dir %s\n", ftp->prevpath);
} }
else else {
ftp->prevpath = NULL; /* no path */ ftp->prevpath = NULL; /* no path */
free(path); free(path);
}
/* free the dir tree and file parts */ /* free the dir tree and file parts */
freedirs(ftp); freedirs(ftp);