add_rev_cmdline(): make a copy of the name argument
authorMichael Haggerty <mhagger@alum.mit.edu>
Sat, 25 May 2013 09:08:02 +0000 (11:08 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 May 2013 16:25:00 +0000 (09:25 -0700)
Instead of assuming that the memory pointed to by the name argument
will live forever, make a local copy of it before storing it in the
ref_cmdline_info.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c
index a67b615bfc7001ac28e339db1d91ea46a1b125b5..25e424cdb694a6f364a626c02aef6cf052999d94 100644 (file)
@@ -898,6 +898,10 @@ static int limit_list(struct rev_info *revs)
        return 0;
 }
 
        return 0;
 }
 
+/*
+ * Add an entry to refs->cmdline with the specified information.
+ * *name is copied.
+ */
 static void add_rev_cmdline(struct rev_info *revs,
                            struct object *item,
                            const char *name,
 static void add_rev_cmdline(struct rev_info *revs,
                            struct object *item,
                            const char *name,
@@ -909,7 +913,7 @@ static void add_rev_cmdline(struct rev_info *revs,
 
        ALLOC_GROW(info->rev, nr + 1, info->alloc);
        info->rev[nr].item = item;
 
        ALLOC_GROW(info->rev, nr + 1, info->alloc);
        info->rev[nr].item = item;
-       info->rev[nr].name = name;
+       info->rev[nr].name = xstrdup(name);
        info->rev[nr].whence = whence;
        info->rev[nr].flags = flags;
        info->nr++;
        info->rev[nr].whence = whence;
        info->rev[nr].flags = flags;
        info->nr++;