Potential memory leak in ldm_volume_dm_create and ldm_volume_dm_remove
functions is fixed. Leak was possible if the caller doesn't want to get
back created or remove device name, passing NULL as a second argument.
---
src/ldm.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/ldm.c b/src/ldm.c
index 02378f8..65606cc 100644
--- a/src/ldm.c
+++ b/src/ldm.c
@@ -3033,6 +3033,8 @@ gboolean
ldm_volume_dm_create(const LDMVolume * const o, GString **created,
GError ** const err)
{
+ if (created) *created = NULL;
+
const LDMVolumePrivate * const vol = o->priv;
/* We should really store the previous logging function and restore it
@@ -3077,14 +3079,22 @@ ldm_volume_dm_create(const LDMVolume * const o, GString
**created,
dm_log_with_errno_init(NULL);
- if (created && name) *created = name;
- return name == NULL ? FALSE : TRUE;
+ gboolean r = name != NULL;
+
+ if (created)
+ *created = name;
+ else if (name)
+ g_string_free(name, TRUE);
+
+ return r;
}
gboolean
ldm_volume_dm_remove(const LDMVolume * const o, GString **removed,
GError ** const err)
{
+ if (removed) *removed = NULL;
+
const LDMVolumePrivate * const vol = o->priv;
/* We should really store the previous logging function and restore it
@@ -3129,7 +3139,11 @@ ldm_volume_dm_remove(const LDMVolume * const o, GString **removed,
out:
dm_tree_free(tree);
- if (removed && name) *removed = name;
+
+ if (removed)
+ *removed = name;
+ else if (name)
+ g_string_free(name, TRUE);
dm_log_with_errno_init(NULL);
--
2.17.0