mirror of
https://github.com/git/git.git
synced 2026-01-09 01:34:00 +00:00
Merge branch 'jk/sparse-leakfix'
Many memory leaks in the sparse-checkout code paths have been plugged. * jk/sparse-leakfix: sparse-checkout: free duplicate hashmap entries sparse-checkout: free string list after displaying sparse-checkout: free pattern list in sparse_checkout_list() sparse-checkout: free sparse_filename after use sparse-checkout: refactor temporary sparse_checkout_patterns sparse-checkout: always free "line" strbuf after reading input sparse-checkout: reuse --stdin buffer when reading patterns dir.c: always copy input to add_pattern() dir.c: free removed sparse-pattern hashmap entries sparse-checkout: clear patterns when init() sees existing sparse file dir.c: free strings in sparse cone pattern hashmaps sparse-checkout: pass string literals directly to add_pattern() sparse-checkout: free string list in write_cone_to_file()
This commit is contained in:
42
dir.c
42
dir.c
@@ -733,6 +733,17 @@ static char *dup_and_filter_pattern(const char *pattern)
|
||||
return result;
|
||||
}
|
||||
|
||||
static void clear_pattern_entry_hashmap(struct hashmap *map)
|
||||
{
|
||||
struct hashmap_iter iter;
|
||||
struct pattern_entry *entry;
|
||||
|
||||
hashmap_for_each_entry(map, &iter, entry, ent) {
|
||||
free(entry->pattern);
|
||||
}
|
||||
hashmap_clear_and_free(map, struct pattern_entry, ent);
|
||||
}
|
||||
|
||||
static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern *given)
|
||||
{
|
||||
struct pattern_entry *translated;
|
||||
@@ -806,6 +817,8 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
|
||||
|
||||
if (given->patternlen > 2 &&
|
||||
!strcmp(given->pattern + given->patternlen - 2, "/*")) {
|
||||
struct pattern_entry *old;
|
||||
|
||||
if (!(given->flags & PATTERN_FLAG_NEGATIVE)) {
|
||||
/* Not a cone pattern. */
|
||||
warning(_("unrecognized pattern: '%s'"), given->pattern);
|
||||
@@ -831,7 +844,11 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
|
||||
}
|
||||
|
||||
hashmap_add(&pl->parent_hashmap, &translated->ent);
|
||||
hashmap_remove(&pl->recursive_hashmap, &translated->ent, &data);
|
||||
old = hashmap_remove_entry(&pl->recursive_hashmap, translated, ent, &data);
|
||||
if (old) {
|
||||
free(old->pattern);
|
||||
free(old);
|
||||
}
|
||||
free(data);
|
||||
return;
|
||||
}
|
||||
@@ -862,8 +879,8 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
|
||||
|
||||
clear_hashmaps:
|
||||
warning(_("disabling cone pattern matching"));
|
||||
hashmap_clear_and_free(&pl->parent_hashmap, struct pattern_entry, ent);
|
||||
hashmap_clear_and_free(&pl->recursive_hashmap, struct pattern_entry, ent);
|
||||
clear_pattern_entry_hashmap(&pl->recursive_hashmap);
|
||||
clear_pattern_entry_hashmap(&pl->parent_hashmap);
|
||||
pl->use_cone_patterns = 0;
|
||||
}
|
||||
|
||||
@@ -915,12 +932,7 @@ void add_pattern(const char *string, const char *base,
|
||||
int nowildcardlen;
|
||||
|
||||
parse_path_pattern(&string, &patternlen, &flags, &nowildcardlen);
|
||||
if (flags & PATTERN_FLAG_MUSTBEDIR) {
|
||||
FLEXPTR_ALLOC_MEM(pattern, pattern, string, patternlen);
|
||||
} else {
|
||||
pattern = xmalloc(sizeof(*pattern));
|
||||
pattern->pattern = string;
|
||||
}
|
||||
FLEX_ALLOC_MEM(pattern, pattern, string, patternlen);
|
||||
pattern->patternlen = patternlen;
|
||||
pattern->nowildcardlen = nowildcardlen;
|
||||
pattern->base = base;
|
||||
@@ -962,9 +974,8 @@ void clear_pattern_list(struct pattern_list *pl)
|
||||
for (i = 0; i < pl->nr; i++)
|
||||
free(pl->patterns[i]);
|
||||
free(pl->patterns);
|
||||
free(pl->filebuf);
|
||||
hashmap_clear_and_free(&pl->recursive_hashmap, struct pattern_entry, ent);
|
||||
hashmap_clear_and_free(&pl->parent_hashmap, struct pattern_entry, ent);
|
||||
clear_pattern_entry_hashmap(&pl->recursive_hashmap);
|
||||
clear_pattern_entry_hashmap(&pl->parent_hashmap);
|
||||
|
||||
memset(pl, 0, sizeof(*pl));
|
||||
}
|
||||
@@ -1162,6 +1173,7 @@ static int add_patterns(const char *fname, const char *base, int baselen,
|
||||
}
|
||||
|
||||
add_patterns_from_buffer(buf, size, base, baselen, pl);
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1169,16 +1181,15 @@ static int add_patterns_from_buffer(char *buf, size_t size,
|
||||
const char *base, int baselen,
|
||||
struct pattern_list *pl)
|
||||
{
|
||||
char *orig = buf;
|
||||
int i, lineno = 1;
|
||||
char *entry;
|
||||
|
||||
hashmap_init(&pl->recursive_hashmap, pl_hashmap_cmp, NULL, 0);
|
||||
hashmap_init(&pl->parent_hashmap, pl_hashmap_cmp, NULL, 0);
|
||||
|
||||
pl->filebuf = buf;
|
||||
|
||||
if (skip_utf8_bom(&buf, size))
|
||||
size -= buf - pl->filebuf;
|
||||
size -= buf - orig;
|
||||
|
||||
entry = buf;
|
||||
|
||||
@@ -1225,6 +1236,7 @@ int add_patterns_from_blob_to_list(
|
||||
}
|
||||
|
||||
add_patterns_from_buffer(buf, size, base, baselen, pl);
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user