Merge branch 'rs/plug-leak-in-bundle'
authorJunio C Hamano <gitster@pobox.com>
Tue, 14 Oct 2014 17:50:09 +0000 (10:50 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Oct 2014 17:50:10 +0000 (10:50 -0700)
* rs/plug-leak-in-bundle:
bundle: plug minor memory leak in is_tag_in_date_range()

1  2 
bundle.c
diff --combined bundle.c
index 891a3cacda457fcb83b511ad0f7d07e7feb64cf4,643b8b8b2ea37408be204069affc99a018bfb578..9a22ab5c02582fbdb3eb36f2142c03ce33bcfc95
+++ b/bundle.c
@@@ -1,5 -1,4 +1,5 @@@
  #include "cache.h"
 +#include "lockfile.h"
  #include "bundle.h"
  #include "object.h"
  #include "commit.h"
@@@ -210,26 -209,29 +210,29 @@@ static int is_tag_in_date_range(struct 
  {
        unsigned long size;
        enum object_type type;
-       char *buf, *line, *lineend;
+       char *buf = NULL, *line, *lineend;
        unsigned long date;
+       int result = 1;
  
        if (revs->max_age == -1 && revs->min_age == -1)
-               return 1;
+               goto out;
  
        buf = read_sha1_file(tag->sha1, &type, &size);
        if (!buf)
-               return 1;
+               goto out;
        line = memmem(buf, size, "\ntagger ", 8);
        if (!line++)
-               return 1;
+               goto out;
        lineend = memchr(line, '\n', buf + size - line);
        line = memchr(line, '>', lineend ? lineend - line : buf + size - line);
        if (!line++)
-               return 1;
+               goto out;
        date = strtoul(line, NULL, 10);
-       free(buf);
-       return (revs->max_age == -1 || revs->max_age < date) &&
+       result = (revs->max_age == -1 || revs->max_age < date) &&
                (revs->min_age == -1 || revs->min_age > date);
+ out:
+       free(buf);
+       return result;
  }
  
  int create_bundle(struct bundle_header *header, const char *path,
        int i, ref_count = 0;
        struct strbuf buf = STRBUF_INIT;
        struct rev_info revs;
 -      struct child_process rls;
 +      struct child_process rls = CHILD_PROCESS_INIT;
        FILE *rls_fout;
  
        bundle_to_stdout = !strcmp(path, "-");
        init_revisions(&revs, NULL);
  
        /* write prerequisites */
 -      memset(&rls, 0, sizeof(rls));
        argv_array_pushl(&rls.args,
                         "rev-list", "--boundary", "--pretty=oneline",
                         NULL);
@@@ -417,13 -420,14 +420,13 @@@ int unbundle(struct bundle_header *head
  {
        const char *argv_index_pack[] = {"index-pack",
                                         "--fix-thin", "--stdin", NULL, NULL};
 -      struct child_process ip;
 +      struct child_process ip = CHILD_PROCESS_INIT;
  
        if (flags & BUNDLE_VERBOSE)
                argv_index_pack[3] = "-v";
  
        if (verify_bundle(header, 0))
                return -1;
 -      memset(&ip, 0, sizeof(ip));
        ip.argv = argv_index_pack;
        ip.in = bundle_fd;
        ip.no_stdout = 1;