From ab1b54c3e3244c481a1f8bf5e7c8b48870846bd8 Mon Sep 17 00:00:00 2001 From: "Bryn M. Reeves" Date: Mon, 7 Sep 2015 12:08:34 +0100 Subject: [PATCH] libdm: fix dm_stats leak in dm_stats_create() The histogram changes adds a new error path to dm_stats_create(). Make sure that the dm_stats handle is properly destroyed if we fail to create the histogram pool and check for failures setting the program_id. --- libdm/libdm-stats.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c index bb26c46a4..20e3c9b23 100644 --- a/libdm/libdm-stats.c +++ b/libdm/libdm-stats.c @@ -144,17 +144,24 @@ struct dm_stats *dm_stats_create(const char *program_id) return_NULL; /* FIXME: better hint. */ - if (!(dms->mem = dm_pool_create("stats_pool", 4096))) - goto_bad; + if (!(dms->mem = dm_pool_create("stats_pool", 4096))) { + dm_free(dms); + return_NULL; + } if (!(dms->hist_mem = dm_pool_create("histogram_pool", hist_hint))) - return_0; + goto_bad; if (!program_id || !strlen(program_id)) dms->program_id = _program_id_from_proc(); else dms->program_id = dm_strdup(program_id); + if (!dms->program_id) { + dm_pool_destroy(dms->hist_mem); + goto_bad; + } + dms->major = -1; dms->minor = -1; dms->name = NULL; @@ -171,6 +178,7 @@ struct dm_stats *dm_stats_create(const char *program_id) return dms; bad: + dm_pool_destroy(dms->mem); dm_free(dms); return NULL; }