Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2020-08-25 00:54:33 +0300
committerJunio C Hamano <gitster@pobox.com>2020-08-25 00:54:34 +0300
commitad00f44f5479441da59bd55261ae717fcb357938 (patch)
tree68f77a1bfd9deb6b5a88b937e27ab5e5b7400e59 /dir.c
parent51226147d16d59243957cb3bc1b2313f9f740725 (diff)
parenteceba5321410bbcc9e0b11e6aa479832f574eca8 (diff)
Merge branch 'en/dir-clear'
Leakfix with code clean-up. * en/dir-clear: dir: fix problematic API to avoid memory leaks dir: make clear_directory() free all relevant memory
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/dir.c b/dir.c
index 502617b134..abb071a7a2 100644
--- a/dir.c
+++ b/dir.c
@@ -54,6 +54,11 @@ static enum path_treatment read_directory_recursive(struct dir_struct *dir,
static int resolve_dtype(int dtype, struct index_state *istate,
const char *path, int len);
+void dir_init(struct dir_struct *dir)
+{
+ memset(dir, 0, sizeof(*dir));
+}
+
int count_slashes(const char *s)
{
int cnt = 0;
@@ -3012,10 +3017,10 @@ int remove_path(const char *name)
}
/*
- * Frees memory within dir which was allocated for exclude lists and
- * the exclude_stack. Does not free dir itself.
+ * Frees memory within dir which was allocated, and resets fields for further
+ * use. Does not free dir itself.
*/
-void clear_directory(struct dir_struct *dir)
+void dir_clear(struct dir_struct *dir)
{
int i, j;
struct exclude_list_group *group;
@@ -3033,6 +3038,13 @@ void clear_directory(struct dir_struct *dir)
free(group->pl);
}
+ for (i = 0; i < dir->ignored_nr; i++)
+ free(dir->ignored[i]);
+ for (i = 0; i < dir->nr; i++)
+ free(dir->entries[i]);
+ free(dir->ignored);
+ free(dir->entries);
+
stk = dir->exclude_stack;
while (stk) {
struct exclude_stack *prev = stk->prev;
@@ -3040,6 +3052,8 @@ void clear_directory(struct dir_struct *dir)
stk = prev;
}
strbuf_release(&dir->basebuf);
+
+ dir_init(dir);
}
struct ondisk_untracked_cache {