add_rev_cmdline(): make a copy of the name argument

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>

Michael Haggerty committed May 25, 2013 at 11:08 UTC df835d3a0c013b9ef912172663c7c58dad87164d
1 file changed +5 -1
revision.c
+5 -1
@@ -898,6 +898,10 @@ static int limit_list(struct rev_info *revs)
898 return 0;
899 }
900
901 +/*
902 + * Add an entry to refs->cmdline with the specified information.
903 + * *name is copied.
904 + */
905 static void add_rev_cmdline(struct rev_info *revs,
906 struct object *item,
907 const char *name,
@@ -909,7 +913,7 @@ static void add_rev_cmdline(struct rev_info *revs,
913
914 ALLOC_GROW(info->rev, nr + 1, info->alloc);
915 info->rev[nr].item = item;
912 - info->rev[nr].name = name;
916 + info->rev[nr].name = xstrdup(name);
917 info->rev[nr].whence = whence;
918 info->rev[nr].flags = flags;
919 info->nr++;