]> granicus.if.org Git - curl/commitdiff
Don't free too much in freedirs() if realloc() fails.
authorGisle Vanem <gvanem@broadpark.no>
Tue, 8 Feb 2005 12:32:28 +0000 (12:32 +0000)
committerGisle Vanem <gvanem@broadpark.no>
Tue, 8 Feb 2005 12:32:28 +0000 (12:32 +0000)
lib/ftp.c

index ddbd4968f9a17e59e766889a4d97d39cd4a1b94f..b29ae5363a980b400b486e7c41e766c2915d5af8 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -2754,10 +2754,9 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
 
   ftp->dirdepth = 0;
   ftp->diralloc = 5; /* default dir depth to allocate */
-  ftp->dirs = (char **)malloc(ftp->diralloc * sizeof(ftp->dirs[0]));
+  ftp->dirs = (char **)calloc(ftp->diralloc, sizeof(ftp->dirs[0]));
   if(!ftp->dirs)
     return CURLE_OUT_OF_MEMORY;
-  ftp->dirs[0] = NULL; /* to start with */
 
   /* parse the URL path into separate path components */
   while((slash_pos=strchr(cur_pos, '/'))) {
@@ -2795,6 +2794,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
         ftp->diralloc *= 2; /* double the size each time */
         bigger = realloc(ftp->dirs, ftp->diralloc * sizeof(ftp->dirs[0]));
         if(!bigger) {
+          ftp->dirdepth--;
           freedirs(ftp);
           return CURLE_OUT_OF_MEMORY;
         }