There are reasons that dm_get_info() can fail other than the multipath device not existing. If there is an existing dm_info structure and the call fails, don't free it. Signed-off-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx> --- libmultipath/devmapper.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index c0eb3351..6d24a2be 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -1590,22 +1590,26 @@ alloc_dminfo (void) } int -dm_get_info (const char * mapname, struct dm_info ** dmi) +dm_get_info (const char * mapname, struct dm_info ** dmi_p) { + struct dm_info *dmi = NULL; + if (!mapname) return 1; - if (!*dmi) - *dmi = alloc_dminfo(); - - if (!*dmi) - return 1; + if (!*dmi_p) { + dmi = alloc_dminfo(); + if (!dmi) + return 1; + } else + dmi = *dmi_p; - if (do_get_info(mapname, *dmi) != 0) { - free(*dmi); - *dmi = NULL; + if (do_get_info(mapname, dmi) != 0) { + if (!*dmi_p) + free(dmi); return 1; - } + } else if (!*dmi_p) + *dmi_p = dmi; return 0; } -- 2.17.2 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://listman.redhat.com/mailman/listinfo/dm-devel