diff options
author | Junio C Hamano <gitster@pobox.com> | 2020-08-24 23:54:33 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2020-08-24 23:54:34 +0200 |
commit | ad00f44f5479441da59bd55261ae717fcb357938 (patch) | |
tree | 68f77a1bfd9deb6b5a88b937e27ab5e5b7400e59 /dir.c | |
parent | Merge branch 'rs/patch-id-with-incomplete-line' (diff) | |
parent | dir: fix problematic API to avoid memory leaks (diff) | |
download | git-ad00f44f5479441da59bd55261ae717fcb357938.tar.xz git-ad00f44f5479441da59bd55261ae717fcb357938.zip |
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.c | 20 |
1 files changed, 17 insertions, 3 deletions
@@ -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 { |