From 41a7aa588f449d3b139480b102f510abc5ef7f85 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 16 Nov 2007 01:15:41 -0800 Subject: Fix per-directory exclude handing for "git add" In "dir_struct", each exclusion element in the exclusion stack records a base string (pointer to the beginning with length) so that we can tell where it came from, but this pointer is just pointing at the parameter that is given by the caller to the push_exclude_per_directory() function. While read_directory_recursive() runs, calls to excluded() makes use the data in the exclusion elements, including this base string. The caller of read_directory_recursive() is not supposed to free the buffer it gave to push_exclude_per_directory() earlier, until it returns. The test case Bruce Stephens gave in the mailing list discussion was simplified and added to the t3700 test. Signed-off-by: Junio C Hamano --- dir.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'dir.c') diff --git a/dir.c b/dir.c index fa9f9021e..225fdfb52 100644 --- a/dir.c +++ b/dir.c @@ -654,6 +654,7 @@ static void free_simplify(struct path_simplify *simplify) int read_directory(struct dir_struct *dir, const char *path, const char *base, int baselen, const char **pathspec) { struct path_simplify *simplify = create_simplify(pathspec); + char *pp = NULL; /* * Make sure to do the per-directory exclude for all the @@ -661,7 +662,8 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i */ if (baselen) { if (dir->exclude_per_dir) { - char *p, *pp = xmalloc(baselen+1); + char *p; + pp = xmalloc(baselen+1); memcpy(pp, base, baselen+1); p = pp; while (1) { @@ -677,12 +679,12 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i else p = pp + baselen; } - free(pp); } } read_directory_recursive(dir, path, base, baselen, 0, simplify); free_simplify(simplify); + free(pp); qsort(dir->entries, dir->nr, sizeof(struct dir_entry *), cmp_name); qsort(dir->ignored, dir->ignored_nr, sizeof(struct dir_entry *), cmp_name); return dir->nr; -- cgit v1.2.1