Commit 0d8c754f authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

better cleaning up of memory in case of failures in the get-loop (it was

taken care of by the exit-free anyway but caused test case 75 and 76 to
report memory leaks).

Also re-indented a small section.
parent 1b802764
Loading
Loading
Loading
Loading
+30 −20
Original line number Original line Diff line number Diff line
@@ -2631,13 +2631,15 @@ operate(struct Configurable *config, int argc, char *argv[])


  /*
  /*
   * Get a curl handle to use for all forthcoming curl transfers.  Cleanup
   * Get a curl handle to use for all forthcoming curl transfers.  Cleanup
   * when all transfers are done. This is supported with libcurl 7.7 and
   * when all transfers are done.
   * should not be attempted on previous versions.
   */
   */
  curl = curl_easy_init();
  curl = curl_easy_init();
  if(!curl)
  if(!curl)
    return CURLE_FAILED_INIT;
    return CURLE_FAILED_INIT;


  /* After this point, we should call curl_easy_cleanup() if we decide to bail
   * out from this function! */

  urlnode = config->url_list;
  urlnode = config->url_list;


  if(config->headerfile) {
  if(config->headerfile) {
@@ -2680,8 +2682,10 @@ operate(struct Configurable *config, int argc, char *argv[])
      res = glob_url(&urls, url, &urlnum,
      res = glob_url(&urls, url, &urlnum,
                     config->showerror?
                     config->showerror?
                     (config->errors?config->errors:stderr):NULL);
                     (config->errors?config->errors:stderr):NULL);
      if(res != CURLE_OK)
      if(res != CURLE_OK) {
        return res;
        clean_getout(config);
        break;
      }
    }
    }




@@ -2714,10 +2718,17 @@ operate(struct Configurable *config, int argc, char *argv[])
          else
          else
            pc=url;
            pc=url;
          pc = strrchr(pc, '/');
          pc = strrchr(pc, '/');
          outfile = (char *) NULL == pc ? NULL : strdup(pc+1) ;

          if(!outfile) {
          if(pc) {
            /* duplicate the string beyond the slash */
            pc++;
            outfile = *pc ? strdup(pc): NULL;
          }
          if(!outfile || !*outfile) {
            helpf("Remote file name has no length!\n");
            helpf("Remote file name has no length!\n");
            return CURLE_WRITE_ERROR;
            res = CURLE_WRITE_ERROR;
            free(url);
            break;
          }
          }
#if defined(__DJGPP__)
#if defined(__DJGPP__)
          {
          {
@@ -2741,8 +2752,9 @@ operate(struct Configurable *config, int argc, char *argv[])
           file output call */
           file output call */
        
        
        if(config->create_dirs)
        if(config->create_dirs)
          if (-1 == create_dir_hierarchy(outfile))
          if (-1 == create_dir_hierarchy(outfile)) {
            return CURLE_WRITE_ERROR;
            return CURLE_WRITE_ERROR;
          }
        
        
        if(config->resume_from_current) {
        if(config->resume_from_current) {
          /* We're told to continue from where we are now. Get the
          /* We're told to continue from where we are now. Get the
@@ -3230,14 +3242,12 @@ static char *my_get_line(FILE *fp)
   char *nl = NULL;
   char *nl = NULL;
   char *retval = NULL;
   char *retval = NULL;


   do
   do {
   {
     if (NULL == fgets(buf, sizeof(buf), fp))
     if (NULL == fgets(buf, sizeof(buf), fp))
       break;
       break;
     if (NULL == retval)
     if (NULL == retval)
       retval = strdup(buf);
       retval = strdup(buf);
      else
     else {
      {
       if (NULL == (retval = realloc(retval,
       if (NULL == (retval = realloc(retval,
                                     strlen(retval) + strlen(buf) + 1)))
                                     strlen(retval) + strlen(buf) + 1)))
         break;
         break;