* [Qemu-devel] [PATCH v2] virtio: Fix memory leaks reported by Coverity
@ 2015-03-14 10:45 Stefan Weil
2015-03-16 8:32 ` Aneesh Kumar K.V
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Weil @ 2015-03-14 10:45 UTC (permalink / raw)
To: QEMU Developer; +Cc: Stefan Weil, Aneesh Kumar K.V, Michael S. Tsirkin
All four leaks are similar, so fix them in one patch.
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
v1 only fixed one of those leaks.
v2 fixes all similar leaks.
hw/9pfs/virtio-9p-local.c | 28 ++++++++--------------------
1 file changed, 8 insertions(+), 20 deletions(-)
diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c
index d05c917..d66abcd 100644
--- a/hw/9pfs/virtio-9p-local.c
+++ b/hw/9pfs/virtio-9p-local.c
@@ -488,7 +488,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
int err = -1;
int serrno = 0;
V9fsString fullname;
- char *buffer;
+ char *buffer = NULL;
v9fs_string_init(&fullname);
v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
@@ -499,7 +499,6 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
buffer = rpath(fs_ctx, path);
err = mknod(buffer, SM_LOCAL_MODE_BITS|S_IFREG, 0);
if (err == -1) {
- g_free(buffer);
goto out;
}
err = local_set_xattr(buffer, credp);
@@ -512,7 +511,6 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
buffer = rpath(fs_ctx, path);
err = mknod(buffer, SM_LOCAL_MODE_BITS|S_IFREG, 0);
if (err == -1) {
- g_free(buffer);
goto out;
}
err = local_set_mapped_file_attr(fs_ctx, path, credp);
@@ -525,7 +523,6 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
buffer = rpath(fs_ctx, path);
err = mknod(buffer, credp->fc_mode, credp->fc_rdev);
if (err == -1) {
- g_free(buffer);
goto out;
}
err = local_post_create_passthrough(fs_ctx, path, credp);
@@ -539,8 +536,8 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
err_end:
remove(buffer);
errno = serrno;
- g_free(buffer);
out:
+ g_free(buffer);
v9fs_string_free(&fullname);
return err;
}
@@ -552,7 +549,7 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
int err = -1;
int serrno = 0;
V9fsString fullname;
- char *buffer;
+ char *buffer = NULL;
v9fs_string_init(&fullname);
v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
@@ -563,7 +560,6 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
buffer = rpath(fs_ctx, path);
err = mkdir(buffer, SM_LOCAL_DIR_MODE_BITS);
if (err == -1) {
- g_free(buffer);
goto out;
}
credp->fc_mode = credp->fc_mode|S_IFDIR;
@@ -576,7 +572,6 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
buffer = rpath(fs_ctx, path);
err = mkdir(buffer, SM_LOCAL_DIR_MODE_BITS);
if (err == -1) {
- g_free(buffer);
goto out;
}
credp->fc_mode = credp->fc_mode|S_IFDIR;
@@ -590,7 +585,6 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
buffer = rpath(fs_ctx, path);
err = mkdir(buffer, credp->fc_mode);
if (err == -1) {
- g_free(buffer);
goto out;
}
err = local_post_create_passthrough(fs_ctx, path, credp);
@@ -604,8 +598,8 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
err_end:
remove(buffer);
errno = serrno;
- g_free(buffer);
out:
+ g_free(buffer);
v9fs_string_free(&fullname);
return err;
}
@@ -659,7 +653,7 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
int err = -1;
int serrno = 0;
V9fsString fullname;
- char *buffer;
+ char *buffer = NULL;
/*
* Mark all the open to not follow symlinks
@@ -675,7 +669,6 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
buffer = rpath(fs_ctx, path);
fd = open(buffer, flags, SM_LOCAL_MODE_BITS);
if (fd == -1) {
- g_free(buffer);
err = fd;
goto out;
}
@@ -690,7 +683,6 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
buffer = rpath(fs_ctx, path);
fd = open(buffer, flags, SM_LOCAL_MODE_BITS);
if (fd == -1) {
- g_free(buffer);
err = fd;
goto out;
}
@@ -706,7 +698,6 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
buffer = rpath(fs_ctx, path);
fd = open(buffer, flags, credp->fc_mode);
if (fd == -1) {
- g_free(buffer);
err = fd;
goto out;
}
@@ -724,8 +715,8 @@ err_end:
close(fd);
remove(buffer);
errno = serrno;
- g_free(buffer);
out:
+ g_free(buffer);
v9fs_string_free(&fullname);
return err;
}
@@ -738,7 +729,7 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
int serrno = 0;
char *newpath;
V9fsString fullname;
- char *buffer;
+ char *buffer = NULL;
v9fs_string_init(&fullname);
v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
@@ -751,7 +742,6 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
buffer = rpath(fs_ctx, newpath);
fd = open(buffer, O_CREAT|O_EXCL|O_RDWR|O_NOFOLLOW, SM_LOCAL_MODE_BITS);
if (fd == -1) {
- g_free(buffer);
err = fd;
goto out;
}
@@ -781,7 +771,6 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
buffer = rpath(fs_ctx, newpath);
fd = open(buffer, O_CREAT|O_EXCL|O_RDWR|O_NOFOLLOW, SM_LOCAL_MODE_BITS);
if (fd == -1) {
- g_free(buffer);
err = fd;
goto out;
}
@@ -810,7 +799,6 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
buffer = rpath(fs_ctx, newpath);
err = symlink(oldpath, buffer);
if (err) {
- g_free(buffer);
goto out;
}
err = lchown(buffer, credp->fc_uid, credp->fc_gid);
@@ -831,8 +819,8 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
err_end:
remove(buffer);
errno = serrno;
- g_free(buffer);
out:
+ g_free(buffer);
v9fs_string_free(&fullname);
return err;
}
--
1.7.10.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH v2] virtio: Fix memory leaks reported by Coverity
2015-03-14 10:45 [Qemu-devel] [PATCH v2] virtio: Fix memory leaks reported by Coverity Stefan Weil
@ 2015-03-16 8:32 ` Aneesh Kumar K.V
0 siblings, 0 replies; 2+ messages in thread
From: Aneesh Kumar K.V @ 2015-03-16 8:32 UTC (permalink / raw)
To: Stefan Weil, QEMU Developer; +Cc: Michael S. Tsirkin
Stefan Weil <sw@weilnetz.de> writes:
> All four leaks are similar, so fix them in one patch.
Ok had to spent some time to figure out which was the path that was not
freeing memory. So added extra information to commit message.
Success path was not doing memory free.
Applied.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>
> v1 only fixed one of those leaks.
> v2 fixes all similar leaks.
>
> hw/9pfs/virtio-9p-local.c | 28 ++++++++--------------------
> 1 file changed, 8 insertions(+), 20 deletions(-)
>
> diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c
> index d05c917..d66abcd 100644
> --- a/hw/9pfs/virtio-9p-local.c
> +++ b/hw/9pfs/virtio-9p-local.c
> @@ -488,7 +488,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
> int err = -1;
> int serrno = 0;
> V9fsString fullname;
> - char *buffer;
> + char *buffer = NULL;
>
> v9fs_string_init(&fullname);
> v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
> @@ -499,7 +499,6 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
> buffer = rpath(fs_ctx, path);
> err = mknod(buffer, SM_LOCAL_MODE_BITS|S_IFREG, 0);
> if (err == -1) {
> - g_free(buffer);
> goto out;
> }
> err = local_set_xattr(buffer, credp);
> @@ -512,7 +511,6 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
> buffer = rpath(fs_ctx, path);
> err = mknod(buffer, SM_LOCAL_MODE_BITS|S_IFREG, 0);
> if (err == -1) {
> - g_free(buffer);
> goto out;
> }
> err = local_set_mapped_file_attr(fs_ctx, path, credp);
> @@ -525,7 +523,6 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
> buffer = rpath(fs_ctx, path);
> err = mknod(buffer, credp->fc_mode, credp->fc_rdev);
> if (err == -1) {
> - g_free(buffer);
> goto out;
> }
> err = local_post_create_passthrough(fs_ctx, path, credp);
> @@ -539,8 +536,8 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
> err_end:
> remove(buffer);
> errno = serrno;
> - g_free(buffer);
> out:
> + g_free(buffer);
> v9fs_string_free(&fullname);
> return err;
> }
> @@ -552,7 +549,7 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
> int err = -1;
> int serrno = 0;
> V9fsString fullname;
> - char *buffer;
> + char *buffer = NULL;
>
> v9fs_string_init(&fullname);
> v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
> @@ -563,7 +560,6 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
> buffer = rpath(fs_ctx, path);
> err = mkdir(buffer, SM_LOCAL_DIR_MODE_BITS);
> if (err == -1) {
> - g_free(buffer);
> goto out;
> }
> credp->fc_mode = credp->fc_mode|S_IFDIR;
> @@ -576,7 +572,6 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
> buffer = rpath(fs_ctx, path);
> err = mkdir(buffer, SM_LOCAL_DIR_MODE_BITS);
> if (err == -1) {
> - g_free(buffer);
> goto out;
> }
> credp->fc_mode = credp->fc_mode|S_IFDIR;
> @@ -590,7 +585,6 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
> buffer = rpath(fs_ctx, path);
> err = mkdir(buffer, credp->fc_mode);
> if (err == -1) {
> - g_free(buffer);
> goto out;
> }
> err = local_post_create_passthrough(fs_ctx, path, credp);
> @@ -604,8 +598,8 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
> err_end:
> remove(buffer);
> errno = serrno;
> - g_free(buffer);
> out:
> + g_free(buffer);
> v9fs_string_free(&fullname);
> return err;
> }
> @@ -659,7 +653,7 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
> int err = -1;
> int serrno = 0;
> V9fsString fullname;
> - char *buffer;
> + char *buffer = NULL;
>
> /*
> * Mark all the open to not follow symlinks
> @@ -675,7 +669,6 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
> buffer = rpath(fs_ctx, path);
> fd = open(buffer, flags, SM_LOCAL_MODE_BITS);
> if (fd == -1) {
> - g_free(buffer);
> err = fd;
> goto out;
> }
> @@ -690,7 +683,6 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
> buffer = rpath(fs_ctx, path);
> fd = open(buffer, flags, SM_LOCAL_MODE_BITS);
> if (fd == -1) {
> - g_free(buffer);
> err = fd;
> goto out;
> }
> @@ -706,7 +698,6 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
> buffer = rpath(fs_ctx, path);
> fd = open(buffer, flags, credp->fc_mode);
> if (fd == -1) {
> - g_free(buffer);
> err = fd;
> goto out;
> }
> @@ -724,8 +715,8 @@ err_end:
> close(fd);
> remove(buffer);
> errno = serrno;
> - g_free(buffer);
> out:
> + g_free(buffer);
> v9fs_string_free(&fullname);
> return err;
> }
> @@ -738,7 +729,7 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
> int serrno = 0;
> char *newpath;
> V9fsString fullname;
> - char *buffer;
> + char *buffer = NULL;
>
> v9fs_string_init(&fullname);
> v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
> @@ -751,7 +742,6 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
> buffer = rpath(fs_ctx, newpath);
> fd = open(buffer, O_CREAT|O_EXCL|O_RDWR|O_NOFOLLOW, SM_LOCAL_MODE_BITS);
> if (fd == -1) {
> - g_free(buffer);
> err = fd;
> goto out;
> }
> @@ -781,7 +771,6 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
> buffer = rpath(fs_ctx, newpath);
> fd = open(buffer, O_CREAT|O_EXCL|O_RDWR|O_NOFOLLOW, SM_LOCAL_MODE_BITS);
> if (fd == -1) {
> - g_free(buffer);
> err = fd;
> goto out;
> }
> @@ -810,7 +799,6 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
> buffer = rpath(fs_ctx, newpath);
> err = symlink(oldpath, buffer);
> if (err) {
> - g_free(buffer);
> goto out;
> }
> err = lchown(buffer, credp->fc_uid, credp->fc_gid);
> @@ -831,8 +819,8 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
> err_end:
> remove(buffer);
> errno = serrno;
> - g_free(buffer);
> out:
> + g_free(buffer);
> v9fs_string_free(&fullname);
> return err;
> }
> --
> 1.7.10.4
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-03-16 8:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-14 10:45 [Qemu-devel] [PATCH v2] virtio: Fix memory leaks reported by Coverity Stefan Weil
2015-03-16 8:32 ` Aneesh Kumar K.V
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).