@matheusbsbs / matheus-bagliano / commits / 79d722224d
Fork 0

path-list.c: always free strdup'ed paths

Always free .paths if .strdup_paths is set, no matter if the parameter free_items is set or not, plugging a minor memory leak. And to clarify the meaning of the flag, rename it to free_util, since it now only affects the freeing of the .util field. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Aug 15, 2007 at 17:59 UTC 79d722224dbad49a50072f92f823d8b12c2e5707
2 files changed +9 -7
path-list.c
+8 -6
@@ -76,16 +76,18 @@ struct path_list_item *path_list_lookup(const char *path, struct path_list *list
76 return list->items + i;
77 }
78
79 -void path_list_clear(struct path_list *list, int free_items)
79 +void path_list_clear(struct path_list *list, int free_util)
80 {
81 if (list->items) {
82 int i;
83 - if (free_items)
84 - for (i = 0; i < list->nr; i++) {
85 - if (list->strdup_paths)
86 - free(list->items[i].path);
83 + if (list->strdup_paths) {
84 + for (i = 0; i < list->nr; i++)
85 + free(list->items[i].path);
86 + }
87 + if (free_util) {
88 + for (i = 0; i < list->nr; i++)
89 free(list->items[i].util);
88 - }
90 + }
91 free(list->items);
92 }
93 list->items = NULL;
path-list.h
+1 -1
@@ -15,7 +15,7 @@ struct path_list
15 void print_path_list(const char *text, const struct path_list *p);
16
17 int path_list_has_path(const struct path_list *list, const char *path);
18 -void path_list_clear(struct path_list *list, int free_items);
18 +void path_list_clear(struct path_list *list, int free_util);
19 struct path_list_item *path_list_insert(const char *path, struct path_list *list);
20 struct path_list_item *path_list_lookup(const char *path, struct path_list *list);
21