mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
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.
This commit is contained in:
parent
0f5933ecc1
commit
ab1b54c3e3
@ -144,17 +144,24 @@ struct dm_stats *dm_stats_create(const char *program_id)
|
|||||||
return_NULL;
|
return_NULL;
|
||||||
|
|
||||||
/* FIXME: better hint. */
|
/* FIXME: better hint. */
|
||||||
if (!(dms->mem = dm_pool_create("stats_pool", 4096)))
|
if (!(dms->mem = dm_pool_create("stats_pool", 4096))) {
|
||||||
goto_bad;
|
dm_free(dms);
|
||||||
|
return_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!(dms->hist_mem = dm_pool_create("histogram_pool", hist_hint)))
|
if (!(dms->hist_mem = dm_pool_create("histogram_pool", hist_hint)))
|
||||||
return_0;
|
goto_bad;
|
||||||
|
|
||||||
if (!program_id || !strlen(program_id))
|
if (!program_id || !strlen(program_id))
|
||||||
dms->program_id = _program_id_from_proc();
|
dms->program_id = _program_id_from_proc();
|
||||||
else
|
else
|
||||||
dms->program_id = dm_strdup(program_id);
|
dms->program_id = dm_strdup(program_id);
|
||||||
|
|
||||||
|
if (!dms->program_id) {
|
||||||
|
dm_pool_destroy(dms->hist_mem);
|
||||||
|
goto_bad;
|
||||||
|
}
|
||||||
|
|
||||||
dms->major = -1;
|
dms->major = -1;
|
||||||
dms->minor = -1;
|
dms->minor = -1;
|
||||||
dms->name = NULL;
|
dms->name = NULL;
|
||||||
@ -171,6 +178,7 @@ struct dm_stats *dm_stats_create(const char *program_id)
|
|||||||
return dms;
|
return dms;
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
|
dm_pool_destroy(dms->mem);
|
||||||
dm_free(dms);
|
dm_free(dms);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user