Signed-off-by: Adam Spiers <[email protected]>
---
Documentation/technical/api-directory-listing.txt | 2 ++
dir.c | 23 +++++++++++++++++++++--
dir.h | 1 +
3 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/Documentation/technical/api-directory-listing.txt
b/Documentation/technical/api-directory-listing.txt
index 944fc39..e339c18 100644
--- a/Documentation/technical/api-directory-listing.txt
+++ b/Documentation/technical/api-directory-listing.txt
@@ -79,4 +79,6 @@ marked. If you to exclude files, make sure you have loaded
index first.
* Use `dir.entries[]`.
+* Call `free_directory()` when none of the contained elements are no longer in
use.
+
(JC)
diff --git a/dir.c b/dir.c
index ac8c838..80f9b22 100644
--- a/dir.c
+++ b/dir.c
@@ -454,6 +454,12 @@ void add_excludes_from_file(struct dir_struct *dir, const
char *fname)
die("cannot use %s as an exclude file", fname);
}
+static void free_exclude_stack(struct exclude_stack *stk)
+{
+ free(stk->filebuf);
+ free(stk);
+}
+
/*
* Loads the per-directory exclude list for the substring of base
* which has a char length of baselen.
@@ -479,8 +485,7 @@ static void prep_exclude(struct dir_struct *dir, const char
*base, int baselen)
struct exclude *exclude = el->excludes[--el->nr];
free(exclude);
}
- free(stk->filebuf);
- free(stk);
+ free_exclude_stack(stk);
}
/* Read from the parent directories and push them down. */
@@ -1467,3 +1472,17 @@ void free_pathspec(struct pathspec *pathspec)
free(pathspec->items);
pathspec->items = NULL;
}
+
+void free_directory(struct dir_struct *dir)
+{
+ int st;
+ for (st = EXC_CMDL; st <= EXC_FILE; st++)
+ free_excludes(&dir->exclude_list[st]);
+
+ struct exclude_stack *prev, *stk = dir->exclude_stack;
+ while (stk) {
+ prev = stk->prev;
+ free_exclude_stack(stk);
+ stk = prev;
+ }
+}
diff --git a/dir.h b/dir.h
index 81efee4..f7cea9c 100644
--- a/dir.h
+++ b/dir.h
@@ -128,6 +128,7 @@ extern void add_excludes_from_file(struct dir_struct *,
const char *fname);
extern void add_exclude(const char *string, const char *base,
int baselen, struct exclude_list *el, const char *src,
int srcpos);
extern void free_excludes(struct exclude_list *el);
+extern void free_directory(struct dir_struct *dir);
extern int file_exists(const char *);
extern int is_inside_dir(const char *dir);
--
1.7.12.155.ge5750d5.dirty
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html