From f9f5aac123d2244daeff92a692a03da3fea6bd74 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Mon, 10 Aug 2015 10:15:22 +0100 Subject: [PATCH] libdm: fix stats handle leak in dm_stats_create (Coverity) Make sure the newly created handle is freed if we are unable to also create the pool for it. tools/dmsetup.c: 4255 in _stats_list() - Variable "dms" going out of scope leaks the storage it points to. --- libdm/libdm-stats.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c index 64ca23f57..a672e0562 100644 --- a/libdm/libdm-stats.c +++ b/libdm/libdm-stats.c @@ -94,10 +94,10 @@ struct dm_stats *dm_stats_create(const char *program_id) { struct dm_stats *dms = NULL; - if (!(dms = dm_malloc(sizeof(*dms)))) + if (!(dms = dm_zalloc(sizeof(*dms)))) return_NULL; if (!(dms->mem = dm_pool_create("stats_pool", 4096))) - return_NULL; + goto_out; if (!program_id || !strlen(program_id)) dms->program_id = _program_id_from_proc(); @@ -117,6 +117,9 @@ struct dm_stats *dm_stats_create(const char *program_id) dms->regions = NULL; return dms; +out: + dm_free(dms); + return NULL; } /**