From 38ddfe7be525d81481c9150c3b3d1690c1c0c2ed Mon Sep 17 00:00:00 2001 From: Milan Broz Date: Mon, 15 Jun 2009 11:56:31 +0000 Subject: [PATCH] Fix memory leaks in toolcontext error path. E.g. # vgscan Parse error at byte 2360 (line 54): expected a value Failed to load config file /etc/lvm/lvm.conf You have a memory leak (not released memory pool): [0x818c788] library (12 bytes) ... --- WHATS_NEW | 1 + lib/commands/toolcontext.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index c7ad0f8a5..7cd2ea005 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.48 - =============================== + Fix memory leaks in toolcontext error path. Re-instate partial activation support in clustered mode. (2.02.40) Allow metadata correction even when PVs are missing. Use 'lvm lvresize' instead of 'lvresize' in fsadm. diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c index 607b7a5ab..c89fd137d 100644 --- a/lib/commands/toolcontext.c +++ b/lib/commands/toolcontext.c @@ -516,15 +516,15 @@ static void _destroy_tag_configs(struct cmd_context *cmd) { struct config_tree_list *cfl; + dm_list_iterate_items(cfl, &cmd->config_files) { + destroy_config_tree(cfl->cft); + } + if (cmd->cft && cmd->cft->root) { destroy_config_tree(cmd->cft); cmd->cft = NULL; } - dm_list_iterate_items(cfl, &cmd->config_files) { - destroy_config_tree(cfl->cft); - } - dm_list_init(&cmd->config_files); } @@ -1110,6 +1110,14 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived, return cmd; error: + _destroy_tag_configs(cmd); + dev_cache_exit(); + if (cmd->filter) + cmd->filter->destroy(cmd->filter); + if (cmd->mem) + dm_pool_destroy(cmd->mem); + if (cmd->libmem) + dm_pool_destroy(cmd->libmem); dm_free(cmd); return NULL; }