All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: arei.gonglei@huawei.com, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, pbonzini@redhat.com,
	peter.huangpeng@huawei.com, armbru@redhat.com
Subject: Re: [Qemu-trivial] [PATCH 6/9] 9pfs: fix memory leak
Date: Wed, 04 Mar 2015 15:30:28 +0300	[thread overview]
Message-ID: <54F6FAE4.6090709@msgid.tls.msk.ru> (raw)
In-Reply-To: <1425023419-12244-7-git-send-email-arei.gonglei@huawei.com>

27.02.2015 10:50, arei.gonglei@huawei.com wrote:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/9pfs/virtio-9p-local.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c
> index a183eee..bcad4e0 100644
> --- a/hw/9pfs/virtio-9p-local.c
> +++ b/hw/9pfs/virtio-9p-local.c
> @@ -500,7 +500,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);
> @@ -513,7 +512,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);
> @@ -526,7 +524,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);
> @@ -540,8 +537,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;
>  }
> @@ -676,7 +673,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;
>          }
> @@ -691,7 +687,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;
>          }
> @@ -707,7 +702,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;
>          }
> @@ -725,8 +719,8 @@ err_end:
>      close(fd);
>      remove(buffer);
>      errno = serrno;
> -    g_free(buffer);
>  out:
> +    g_free(buffer);
>      v9fs_string_free(&fullname);
>      return err;
>  }

This patch introduces a compiler warning, which is technically
correct:

hw/9pfs/virtio-9p-local.c: In function ‘local_open2’:
hw/9pfs/virtio-9p-local.c:723:5: error: ‘buffer’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     g_free(buffer);
     ^
hw/9pfs/virtio-9p-local.c: In function ‘local_mknod’:
hw/9pfs/virtio-9p-local.c:541:5: error: ‘buffer’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     g_free(buffer);
     ^

This is because `buffer' variable is initialized within one
of the `if' branches but is left uninitialized if none of
the conditions is true.  In reality this can't happen because
at least one condition is always true.

It is a one more reason to rewrite this code like I mentioned
in another mail instead of trying to fix random issues like
this.  I'll try to come up with a patch doing that shortly.
Meanwhile I'll drop this patch.

Thanks,

/mjt


WARNING: multiple messages have this Message-ID (diff)
From: Michael Tokarev <mjt@tls.msk.ru>
To: arei.gonglei@huawei.com, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, pbonzini@redhat.com,
	peter.huangpeng@huawei.com, armbru@redhat.com
Subject: Re: [Qemu-devel] [Qemu-trivial] [PATCH 6/9] 9pfs: fix memory leak
Date: Wed, 04 Mar 2015 15:30:28 +0300	[thread overview]
Message-ID: <54F6FAE4.6090709@msgid.tls.msk.ru> (raw)
In-Reply-To: <1425023419-12244-7-git-send-email-arei.gonglei@huawei.com>

27.02.2015 10:50, arei.gonglei@huawei.com wrote:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/9pfs/virtio-9p-local.c | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c
> index a183eee..bcad4e0 100644
> --- a/hw/9pfs/virtio-9p-local.c
> +++ b/hw/9pfs/virtio-9p-local.c
> @@ -500,7 +500,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);
> @@ -513,7 +512,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);
> @@ -526,7 +524,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);
> @@ -540,8 +537,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;
>  }
> @@ -676,7 +673,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;
>          }
> @@ -691,7 +687,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;
>          }
> @@ -707,7 +702,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;
>          }
> @@ -725,8 +719,8 @@ err_end:
>      close(fd);
>      remove(buffer);
>      errno = serrno;
> -    g_free(buffer);
>  out:
> +    g_free(buffer);
>      v9fs_string_free(&fullname);
>      return err;
>  }

This patch introduces a compiler warning, which is technically
correct:

hw/9pfs/virtio-9p-local.c: In function ‘local_open2’:
hw/9pfs/virtio-9p-local.c:723:5: error: ‘buffer’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     g_free(buffer);
     ^
hw/9pfs/virtio-9p-local.c: In function ‘local_mknod’:
hw/9pfs/virtio-9p-local.c:541:5: error: ‘buffer’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
     g_free(buffer);
     ^

This is because `buffer' variable is initialized within one
of the `if' branches but is left uninitialized if none of
the conditions is true.  In reality this can't happen because
at least one condition is always true.

It is a one more reason to rewrite this code like I mentioned
in another mail instead of trying to fix random issues like
this.  I'll try to come up with a patch doing that shortly.
Meanwhile I'll drop this patch.

Thanks,

/mjt

  parent reply	other threads:[~2015-03-04 12:30 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-27  7:50 [Qemu-trivial] [PATCH 0/9] Coverity defects fixes arei.gonglei
2015-02-27  7:50 ` [Qemu-devel] " arei.gonglei
2015-02-27  7:50 ` [Qemu-trivial] [PATCH 1/9] nbd: fix resource leak arei.gonglei
2015-02-27  7:50   ` [Qemu-devel] " arei.gonglei
2015-02-27  7:50 ` [Qemu-trivial] [PATCH 2/9] arm: fix memory leak arei.gonglei
2015-02-27  7:50   ` [Qemu-devel] " arei.gonglei
2015-02-28  9:52   ` [Qemu-trivial] " Michael Tokarev
2015-02-28  9:52     ` [Qemu-devel] " Michael Tokarev
2015-02-28  9:59     ` [Qemu-trivial] " Gonglei
2015-02-28  9:59       ` [Qemu-devel] " Gonglei
2015-02-28 10:18       ` [Qemu-trivial] " Michael Tokarev
2015-02-28 10:18         ` [Qemu-devel] " Michael Tokarev
2015-02-28 10:21         ` Gonglei
2015-02-28 10:21           ` [Qemu-devel] " Gonglei
2015-03-04 13:16   ` Michael Tokarev
2015-03-04 13:16     ` [Qemu-devel] " Michael Tokarev
2015-03-05  2:26     ` Gonglei
2015-03-05  2:26       ` [Qemu-devel] " Gonglei
2015-03-05  8:47       ` [Qemu-trivial] [Qemu-devel] " Markus Armbruster
2015-03-05  8:47         ` [Qemu-devel] [Qemu-trivial] " Markus Armbruster
2015-03-05  9:43         ` [Qemu-trivial] [Qemu-devel] " Gonglei
2015-03-05  9:43           ` [Qemu-devel] [Qemu-trivial] " Gonglei
2015-02-27  7:50 ` [Qemu-trivial] [PATCH 3/9] sparc/leon3.c: " arei.gonglei
2015-02-27  7:50   ` [Qemu-devel] " arei.gonglei
2015-02-27  7:50 ` [Qemu-trivial] [PATCH 4/9] macio: fix possible " arei.gonglei
2015-02-27  7:50   ` [Qemu-devel] " arei.gonglei
2015-02-27  7:50 ` [Qemu-trivial] [PATCH 5/9] e500: fix " arei.gonglei
2015-02-27  7:50   ` [Qemu-devel] " arei.gonglei
2015-02-28  9:41   ` [Qemu-trivial] " Michael Tokarev
2015-02-28  9:41     ` [Qemu-devel] " Michael Tokarev
2015-02-28  9:57     ` [Qemu-trivial] " Gonglei
2015-02-28  9:57       ` [Qemu-devel] " Gonglei
2015-02-27  7:50 ` [Qemu-trivial] [PATCH 6/9] 9pfs: " arei.gonglei
2015-02-27  7:50   ` [Qemu-devel] " arei.gonglei
2015-02-28  9:46   ` [Qemu-trivial] " Michael Tokarev
2015-02-28  9:46     ` [Qemu-devel] " Michael Tokarev
2015-03-04 12:30   ` Michael Tokarev [this message]
2015-03-04 12:30     ` [Qemu-devel] [Qemu-trivial] " Michael Tokarev
2015-02-27  7:50 ` [Qemu-trivial] [PATCH 7/9] milkymist.c: " arei.gonglei
2015-02-27  7:50   ` [Qemu-devel] " arei.gonglei
2015-02-27  7:50 ` [Qemu-trivial] [PATCH 8/9] sysbus: " arei.gonglei
2015-02-27  7:50   ` [Qemu-devel] " arei.gonglei
2015-02-27  7:50 ` [Qemu-trivial] [PATCH 9/9] microblaze: " arei.gonglei
2015-02-27  7:50   ` [Qemu-devel] " arei.gonglei
2015-02-28  9:54 ` [Qemu-trivial] [PATCH 0/9] Coverity defects fixes Michael Tokarev
2015-02-28  9:54   ` [Qemu-devel] " Michael Tokarev
2015-02-28 10:03   ` [Qemu-trivial] " Gonglei
2015-02-28 10:03     ` [Qemu-devel] " Gonglei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54F6FAE4.6090709@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=arei.gonglei@huawei.com \
    --cc=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.huangpeng@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.