]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Coverity fixes resources leaks
authorNigel Croxon <ncroxon@redhat.com>
Mon, 4 Nov 2024 16:17:46 +0000 (11:17 -0500)
committerMariusz Tkaczyk <mtkaczyk@kernel.org>
Mon, 16 Dec 2024 09:10:45 +0000 (10:10 +0100)
Handle variable going out of scope leaks the handle.

Signed-off-by: Nigel Croxon <ncroxon@redhat.com>
Assemble.c
Incremental.c
bitmap.c

index 37a530eea344b047dbcc757c0672b3106d906bc9..f8099cd32aa3f718d3ab7a091ca30ab38e065d48 100644 (file)
@@ -753,6 +753,7 @@ static int load_devices(struct devs *devices, char *devmap,
                        tst->ss->free_super(tst);
                        free(tst);
                        *stp = st;
+                       free(best);
                        return -1;
                }
                close(dfd);
@@ -834,7 +835,6 @@ static int load_devices(struct devs *devices, char *devmap,
                                       inargv ? "the list" :
                                       "the\n      DEVICE list in mdadm.conf"
                                        );
-                               free(best);
                                *stp = st;
                                goto error;
                        }
@@ -857,6 +857,7 @@ error:
        close(mdfd);
        free(devices);
        free(devmap);
+       free(best);
        return -1;
 
 }
index aa5db3bf1372e5cb5a42f0de690fc10f7c4f5205..9b455a12b0e221f9bec722d2732ef0a13d7fffcc 100644 (file)
@@ -282,7 +282,7 @@ int Incremental(struct mddev_dev *devlist, struct context *c,
                 * clustering resource agents
                 */
                if (info.array.state & (1 << MD_SB_CLUSTERED))
-                       goto out;
+                       goto out_unlock;
 
                /* Couldn't find an existing array, maybe make a new one */
                mdfd = create_mddev(match ? match->devname : NULL, name_to_use, trustworthy,
index c62d18d466b59186b23b2b23753b4501e5f3c65d..3f8da63d570e7ffd5883be38810628410fcfe2b9 100644 (file)
--- a/bitmap.c
+++ b/bitmap.c
@@ -260,8 +260,11 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
                return rv;
 
        info = bitmap_fd_read(fd, brief);
-       if (!info)
+       if (!info) {
+               close_fd(&fd);
+               free(info);
                return rv;
+       }
        sb = &info->sb;
        if (sb->magic != BITMAP_MAGIC) {
                pr_err("This is an md array.  To view a bitmap you need to examine\n");
@@ -336,7 +339,6 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
                printf("    Cluster name : %-64s\n", sb->cluster_name);
                for (i = 0; i < (int)sb->nodes; i++) {
                        st = NULL;
-                       free(info);
                        fd = bitmap_file_open(filename, &st, i, fd);
                        if (fd < 0) {
                                printf("   Unable to open bitmap file on node: %i\n", i);
@@ -347,6 +349,7 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st)
                                printf("   Unable to read bitmap on node: %i\n", i);
                                continue;
                        }
+                       free(sb);
                        sb = &info->sb;
                        if (sb->magic != BITMAP_MAGIC)
                                pr_err("invalid bitmap magic 0x%x, the bitmap file appears to be corrupted\n", sb->magic);