{"thread":{"id":"9537","subject":"[PATCH][RESEND] path-list.c: always free strdup'ed paths","startedAt":"2007-08-15T15:59:24Z","lastAt":"2007-08-15T15:59:24Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"50786","messageId":"46C322DC.9030007@lsrfire.ath.cx","threadId":"9537","inReplyTo":null,"subject":"[PATCH][RESEND] path-list.c: always free strdup'ed paths","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2007-08-15T15:59:24Z","receivedAt":"2007-08-15T15:59:24Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Always free .paths if .strdup_paths is set, no matter if the\nparameter free_items is set or not, plugging a minor memory leak.\nAnd to clarify the meaning of the flag, rename it to free_util,\nsince it now only affects the freeing of the .util field.\n\nSigned-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>\n---\n\n path-list.c |   14 ++++++++------\n path-list.h |    2 +-\n 2 files changed, 9 insertions(+), 7 deletions(-)\n\ndiff --git a/path-list.c b/path-list.c\nindex dcb4b3a..3d83b7b 100644\n--- a/path-list.c\n+++ b/path-list.c\n@@ -76,16 +76,18 @@ struct path_list_item *path_list_lookup(const char *path, struct path_list *list\n \treturn list->items + i;\n }\n \n-void path_list_clear(struct path_list *list, int free_items)\n+void path_list_clear(struct path_list *list, int free_util)\n {\n \tif (list->items) {\n \t\tint i;\n-\t\tif (free_items)\n-\t\t\tfor (i = 0; i < list->nr; i++) {\n-\t\t\t\tif (list->strdup_paths)\n-\t\t\t\t\tfree(list->items[i].path);\n+\t\tif (list->strdup_paths) {\n+\t\t\tfor (i = 0; i < list->nr; i++)\n+\t\t\t\tfree(list->items[i].path);\n+\t\t}\n+\t\tif (free_util) {\n+\t\t\tfor (i = 0; i < list->nr; i++)\n \t\t\t\tfree(list->items[i].util);\n-\t\t\t}\n+\t\t}\n \t\tfree(list->items);\n \t}\n \tlist->items = NULL;\ndiff --git a/path-list.h b/path-list.h\nindex ce5ffab..5931e2c 100644\n--- a/path-list.h\n+++ b/path-list.h\n@@ -15,7 +15,7 @@ struct path_list\n void print_path_list(const char *text, const struct path_list *p);\n \n int path_list_has_path(const struct path_list *list, const char *path);\n-void path_list_clear(struct path_list *list, int free_items);\n+void path_list_clear(struct path_list *list, int free_util);\n struct path_list_item *path_list_insert(const char *path, struct path_list *list);\n struct path_list_item *path_list_lookup(const char *path, struct path_list *list);\n \n"}]}