qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jim Meyering <jim@meyering.net>
To: qemu-devel@nongnu.org
Cc: Jim Meyering <meyering@redhat.com>
Subject: [Qemu-devel] [PATCHv3 2/5] linux-user: do_msgrcv: don't leak host_mb upon TARGET_EFAULT failure
Date: Wed, 22 Aug 2012 13:55:53 +0200	[thread overview]
Message-ID: <1345636556-29008-3-git-send-email-jim@meyering.net> (raw)
In-Reply-To: <1345636556-29008-1-git-send-email-jim@meyering.net>

From: Jim Meyering <meyering@redhat.com>

Also, use g_malloc to avoid NULL-deref upon OOM.

Signed-off-by: Jim Meyering <meyering@redhat.com>
---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 41c869b..1174306 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -2848,7 +2848,7 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
     if (!lock_user_struct(VERIFY_WRITE, target_mb, msgp, 0))
         return -TARGET_EFAULT;

-    host_mb = malloc(msgsz+sizeof(long));
+    host_mb = g_malloc(msgsz+sizeof(long));
     ret = get_errno(msgrcv(msqid, host_mb, msgsz, tswapal(msgtyp), msgflg));

     if (ret > 0) {
@@ -2863,11 +2863,11 @@ static inline abi_long do_msgrcv(int msqid, abi_long msgp,
     }

     target_mb->mtype = tswapal(host_mb->mtype);
-    free(host_mb);

 end:
     if (target_mb)
         unlock_user_struct(target_mb, msgp, 1);
+    g_free(host_mb);
     return ret;
 }

-- 
1.7.12

  parent reply	other threads:[~2012-08-22 11:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-22 11:55 [Qemu-devel] [PATCHv3 0/5] plug memory and file-descriptor leaks Jim Meyering
2012-08-22 11:55 ` [Qemu-devel] [PATCHv3 1/5] qemu-ga: don't leak a file descriptor upon failed lockf Jim Meyering
2012-08-22 11:55 ` Jim Meyering [this message]
2012-08-22 11:55 ` [Qemu-devel] [PATCHv3 3/5] sheepdog: don't leak socket file descriptor upon connection failure Jim Meyering
2012-08-22 11:55 ` [Qemu-devel] [PATCHv3 4/5] arm-semi: don't leak 1KB user string lock buffer upon TARGET_SYS_OPEN Jim Meyering
2012-08-22 11:55 ` [Qemu-devel] [PATCHv3 5/5] softmmu-semi: fix lock_user* functions not to deref NULL upon OOM Jim Meyering

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=1345636556-29008-3-git-send-email-jim@meyering.net \
    --to=jim@meyering.net \
    --cc=meyering@redhat.com \
    --cc=qemu-devel@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 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).