bisect: copy filename string obtained from git_path()
Prevent the string from being overwritten by other callers of git_path() and friends before we are done using it. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Apr 27, 2012 at 00:26 UTC
144e7090045a703c8f5d140474f202ba4f38ac9a
1 file changed
+5
-3
bisect.c
+5
-3
@@ -833,7 +833,7 @@ static int check_ancestors(const char *prefix)
833
*/
834
static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
835
{
836
- const char *filename = git_path("BISECT_ANCESTORS_OK");
836
+ char *filename = xstrdup(git_path("BISECT_ANCESTORS_OK"));
837
struct stat st;
838
int fd;
839
@@ -842,11 +842,11 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
842
843
/* Check if file BISECT_ANCESTORS_OK exists. */
844
if (!stat(filename, &st) && S_ISREG(st.st_mode))
845
- return;
845
+ goto done;
846
847
/* Bisecting with no good rev is ok. */
848
if (good_revs.nr == 0)
849
- return;
849
+ goto done;
850
851
/* Check if all good revs are ancestor of the bad rev. */
852
if (check_ancestors(prefix))
@@ -859,6 +859,8 @@ static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
859
filename, strerror(errno));
860
else
861
close(fd);
862
+ done:
863
+ free(filename);
864
}
865
866
/*