Unverified Commit a1232a57 by Christian Brauner Committed by Stéphane Graber

zfs: fix resource leak

Fixes: Coverity 1461730. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent c89533f4
...@@ -159,8 +159,8 @@ bool zfs_detect(const char *path) ...@@ -159,8 +159,8 @@ bool zfs_detect(const char *path)
int zfs_mount(struct lxc_storage *bdev) int zfs_mount(struct lxc_storage *bdev)
{ {
__do_free char *mntdata = NULL;
unsigned long mntflags = 0; unsigned long mntflags = 0;
char *mntdata = NULL;
int ret; int ret;
size_t oldlen, newlen, totallen; size_t oldlen, newlen, totallen;
char *tmp; char *tmp;
...@@ -176,7 +176,6 @@ int zfs_mount(struct lxc_storage *bdev) ...@@ -176,7 +176,6 @@ int zfs_mount(struct lxc_storage *bdev)
ret = parse_mntopts(bdev->mntopts, &mntflags, &mntdata); ret = parse_mntopts(bdev->mntopts, &mntflags, &mntdata);
if (ret < 0) { if (ret < 0) {
ERROR("Failed to parse mount options"); ERROR("Failed to parse mount options");
free(mntdata);
return -22; return -22;
} }
...@@ -221,7 +220,6 @@ int zfs_mount(struct lxc_storage *bdev) ...@@ -221,7 +220,6 @@ int zfs_mount(struct lxc_storage *bdev)
tmp = realloc(mntdata, totallen); tmp = realloc(mntdata, totallen);
if (!tmp) { if (!tmp) {
ERROR("Failed to reallocate memory"); ERROR("Failed to reallocate memory");
free(mntdata);
return -1; return -1;
} }
mntdata = tmp; mntdata = tmp;
...@@ -229,12 +227,10 @@ int zfs_mount(struct lxc_storage *bdev) ...@@ -229,12 +227,10 @@ int zfs_mount(struct lxc_storage *bdev)
ret = snprintf((mntdata + oldlen), newlen, ",zfsutil,mntpoint=%s", src); ret = snprintf((mntdata + oldlen), newlen, ",zfsutil,mntpoint=%s", src);
if (ret < 0 || (size_t)ret >= newlen) { if (ret < 0 || (size_t)ret >= newlen) {
ERROR("Failed to create string"); ERROR("Failed to create string");
free(mntdata);
return -1; return -1;
} }
ret = mount(src, bdev->dest, "zfs", mntflags, mntdata); ret = mount(src, bdev->dest, "zfs", mntflags, mntdata);
free(mntdata);
if (ret < 0 && errno != EBUSY) { if (ret < 0 && errno != EBUSY) {
SYSERROR("Failed to mount \"%s\" on \"%s\"", src, bdev->dest); SYSERROR("Failed to mount \"%s\" on \"%s\"", src, bdev->dest);
return -1; return -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment