diff --git a/lib/label/hints.c b/lib/label/hints.c index f1a151943..48fb661b4 100644 --- a/lib/label/hints.c +++ b/lib/label/hints.c @@ -356,6 +356,16 @@ void hints_exit(struct cmd_context *cmd) return _unlock_hints(cmd); } +void free_hints(struct dm_list *hints) +{ + struct hint *hint, *hint2; + + dm_list_iterate_items_safe(hint, hint2, hints) { + dm_list_del(&hint->list); + free(hint); + } +} + static struct hint *_find_hint_name(struct dm_list *hints, const char *name) { struct hint *hint; @@ -787,8 +797,10 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int * if (fclose(fp)) stack; - if (!ret) + if (!ret) { + free_hints(hints); return 0; + } if (!found) return 1; diff --git a/lib/label/hints.h b/lib/label/hints.h index 7f47648d6..51143343d 100644 --- a/lib/label/hints.h +++ b/lib/label/hints.h @@ -24,6 +24,8 @@ struct hint { unsigned chosen:1; /* this hint's dev was chosen for scanning */ }; +void free_hints(struct dm_list *hints); + int write_hint_file(struct cmd_context *cmd, int newhints); void clear_hint_file(struct cmd_context *cmd); diff --git a/lib/label/label.c b/lib/label/label.c index 328e4e75b..045831383 100644 --- a/lib/label/label.c +++ b/lib/label/label.c @@ -857,16 +857,6 @@ static int _setup_bcache(void) return 1; } -static void _free_hints(struct dm_list *hints) -{ - struct hint *hint, *hint2; - - dm_list_iterate_items_safe(hint, hint2, hints) { - dm_list_del(&hint->list); - free(hint); - } -} - /* * We don't know how many of num_devs will be PVs that we need to * keep open, but if it's greater than the soft limit, then we'll @@ -1165,7 +1155,7 @@ int label_scan(struct cmd_context *cmd) if (!validate_hints(cmd, &hints_list)) { log_debug("Will scan %d remaining devices", dm_list_size(&all_devs)); _scan_list(cmd, cmd->filter, &all_devs, NULL); - _free_hints(&hints_list); + free_hints(&hints_list); using_hints = 0; create_hints = 0; } else {