kpartx: Fix memory leak of uuid found by coverity
authorBenjamin Marzinski <bmarzins@redhat.com>
Wed, 1 Aug 2018 20:56:59 +0000 (15:56 -0500)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Tue, 7 Aug 2018 13:30:25 +0000 (15:30 +0200)
After the call to make_prefixed_uuid() allocs uuid, it must be freed if
dm_find_part() fails.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
kpartx/devmapper.c

index f94d70e..cd33449 100644 (file)
@@ -663,7 +663,7 @@ int dm_find_part(const char *parent, const char *delim, int part,
 
        tmp = dm_find_uuid(uuid);
        if (tmp == NULL)
-               return r;
+               goto out;
 
        /* Sanity check on partition, see dm_foreach_partmaps */
        if (dm_type(tmp, "linear") != 1)
@@ -689,13 +689,14 @@ int dm_find_part(const char *parent, const char *delim, int part,
                       tmp, uuid, name);
 
        r = dm_rename(tmp, name);
-       if (r == 0) {
-               free(uuid);
-               if (verbose)
-                       fprintf(stderr, "renaming %s->%s failed\n", tmp, name);
-       } else
+       if (r == 1) {
                *part_uuid = uuid;
+               return 1;
+       }
+       if (verbose)
+               fprintf(stderr, "renaming %s->%s failed\n", tmp, name);
 out:
+       free(uuid);
        free(tmp);
        return r;
 }