]> git.proxmox.com Git - qemu.git/commitdiff
linux-user: do_msgrcv: don't leak host_mb upon TARGET_EFAULT failure
authorJim Meyering <meyering@redhat.com>
Wed, 22 Aug 2012 11:55:53 +0000 (13:55 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Wed, 22 Aug 2012 15:47:14 +0000 (10:47 -0500)
Also, use g_malloc to avoid NULL-deref upon OOM.

Signed-off-by: Jim Meyering <meyering@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
linux-user/syscall.c

index 41c869bfe043a95db32c259cfc45db6c88dd0458..11743065e934475cfdb24eed093f048e68982ad6 100644 (file)
@@ -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;
 }