]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
zfs: fix resource leak
authorChristian Brauner <christian.brauner@ubuntu.com>
Wed, 15 Apr 2020 11:56:24 +0000 (13:56 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 15 Apr 2020 12:10:30 +0000 (14:10 +0200)
Fixes: Coverity 1461730.
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/storage/zfs.c

index 4cc171fd808aece9cbc3273ec6a72df5b23cfd39..ee9e32d0a62317fcec18ce11ad1641b7ac56b26a 100644 (file)
@@ -159,8 +159,8 @@ bool zfs_detect(const char *path)
 
 int zfs_mount(struct lxc_storage *bdev)
 {
+       __do_free char *mntdata = NULL;
        unsigned long mntflags = 0;
-       char *mntdata = NULL;
        int ret;
        size_t oldlen, newlen, totallen;
        char *tmp;
@@ -176,7 +176,6 @@ int zfs_mount(struct lxc_storage *bdev)
        ret = parse_mntopts(bdev->mntopts, &mntflags, &mntdata);
        if (ret < 0) {
                ERROR("Failed to parse mount options");
-               free(mntdata);
                return -22;
        }
 
@@ -221,7 +220,6 @@ int zfs_mount(struct lxc_storage *bdev)
        tmp = realloc(mntdata, totallen);
        if (!tmp) {
                ERROR("Failed to reallocate memory");
-               free(mntdata);
                return -1;
        }
        mntdata = tmp;
@@ -229,12 +227,10 @@ int zfs_mount(struct lxc_storage *bdev)
        ret = snprintf((mntdata + oldlen), newlen, ",zfsutil,mntpoint=%s", src);
        if (ret < 0 || (size_t)ret >= newlen) {
                ERROR("Failed to create string");
-               free(mntdata);
                return -1;
        }
 
        ret = mount(src, bdev->dest, "zfs", mntflags, mntdata);
-       free(mntdata);
        if (ret < 0 && errno != EBUSY) {
                SYSERROR("Failed to mount \"%s\" on \"%s\"", src, bdev->dest);
                return -1;