From: Daniel Stenberg Date: Fri, 17 Dec 2004 10:09:32 +0000 (+0000) Subject: avoid an extra malloc X-Git-Tag: curl-7_12_3~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e3d342df961050ea8b2c20fe9213f3f645360708;p=curl avoid an extra malloc --- diff --git a/lib/ftp.c b/lib/ftp.c index 5016a6a80..0aa734e5b 100644 --- a/lib/ftp.c +++ b/lib/ftp.c @@ -778,19 +778,16 @@ CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status) flen = ftp->file?strlen(ftp->file):0; /* file is "raw" already */ dlen = strlen(path)-flen; if(dlen) { - ftp->prevpath = malloc(dlen + 1); - if(!ftp->prevpath) { - free(path); - return CURLE_OUT_OF_MEMORY; - } - memcpy(ftp->prevpath, path, dlen); - ftp->prevpath[dlen]=0; /* terminate */ + ftp->prevpath = path; + if(flen) + /* if 'path' is not the whole string */ + ftp->prevpath[dlen]=0; /* terminate */ infof(data, "Remembering we are in dir %s\n", ftp->prevpath); } - else + else { ftp->prevpath = NULL; /* no path */ - free(path); - + free(path); + } /* free the dir tree and file parts */ freedirs(ftp);