mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
str_list: add str_list_destroy function
The str_list_destroy function may be called to cleanup memory when the list is not used anymore and the list itself was not allocated from the memory pool.
This commit is contained in:
parent
0d5b1294f0
commit
77605457e7
@ -247,3 +247,16 @@ bad:
|
||||
dm_pool_free(mem, list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void str_list_destroy(struct dm_list *list, int deallocate_strings)
|
||||
{
|
||||
struct dm_str_list *sl, *tmp_sl;
|
||||
|
||||
dm_list_iterate_items_safe(sl, tmp_sl, list) {
|
||||
dm_list_del(&sl->list);
|
||||
if (deallocate_strings)
|
||||
dm_free((char *)sl->str);
|
||||
dm_free(sl);
|
||||
}
|
||||
dm_free(list);
|
||||
}
|
||||
|
@ -32,5 +32,7 @@ int str_list_dup(struct dm_pool *mem, struct dm_list *sllnew,
|
||||
const struct dm_list *sllold);
|
||||
char *str_list_to_str(struct dm_pool *mem, const struct dm_list *list, const char *delim);
|
||||
struct dm_list *str_to_str_list(struct dm_pool *mem, const char *str, const char *delim, int ignore_multiple_delim);
|
||||
/* Only for lists which were *not* allocated from the mem pool! */
|
||||
void str_list_destroy(struct dm_list *list, int deallocate_strings);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user