qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Harmandeep Kaur <write.harmandeep@gmail.com>, qemu-devel@nongnu.org
Cc: Stefan Hajnoczi <stefanha@gmail.com>, riku.voipio@iki.fi
Subject: Re: [Qemu-devel] [PATCH] linux-user/syscall.c: malloc()/calloc() to g_malloc()/g_try_malloc()/g_new0()
Date: Thu, 1 Oct 2015 09:51:38 -0600	[thread overview]
Message-ID: <560D568A.5090005@redhat.com> (raw)
In-Reply-To: <CAPtdW17iA8ucfi0CYhtVGSfJ6RYSdu-NMT1gCqCBU8rHTGSTUQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2153 bytes --]

On 09/30/2015 08:32 AM, Harmandeep Kaur wrote:
> Convert malloc()/calloc() calls to g_malloc()/g_try_malloc()/g_new0()
> in linux-user/syscall.c file
> 
> Signed-off-by: Harmandeep Kaur <write.harmandeep@gmail.com>
> ---
>  linux-user/syscall.c | 36 ++++++++++--------------------------
>  1 file changed, 10 insertions(+), 26 deletions(-)
> 
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index d1d3eb2..55a0a7a 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -1554,12 +1554,7 @@ set_timeout:
>                  }
> 
>                  fprog.len = tswap16(tfprog->len);
> -                filter = malloc(fprog.len * sizeof(*filter));
> -                if (filter == NULL) {
> -                    unlock_user_struct(tfilter, tfprog->filter, 1);
> -                    unlock_user_struct(tfprog, optval_addr, 1);
> -                    return -TARGET_ENOMEM;
> -                }
> +                filter = g_malloc(fprog.len * sizeof(*filter));

Please consider using g_new(TYPE, fprog.len) - see commit 97f3ad35 (and
lots others) for reasons why.

> @@ -2672,14 +2663,11 @@ static inline abi_long target_to_host_semarray(int
> semid, unsigned short **host_
> 
>      nsems = semid_ds.sem_nsems;
> 
> -    *host_array = malloc(nsems*sizeof(unsigned short));
> -    if (!*host_array) {
> -        return -TARGET_ENOMEM;
> -    }
> +    *host_array = g_malloc(nsems*sizeof(unsigned short));

and again here (not to mention that it would fix the lack of spaces
around binary *)

> @@ -2975,15 +2963,11 @@ static inline abi_long do_msgsnd(int msqid,
> abi_long msgp,
> 
>      if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0))
>          return -TARGET_EFAULT;
> -    host_mb = malloc(msgsz+sizeof(long));
> -    if (!host_mb) {
> -        unlock_user_struct(target_mb, msgp, 0);
> -        return -TARGET_ENOMEM;
> -    }
> +    host_mb = g_malloc(msgsz+sizeof(long));

As long as you are touching this, spaces around binary + would be nice.


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

      parent reply	other threads:[~2015-10-01 15:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-30 14:32 [Qemu-devel] [PATCH] linux-user/syscall.c: malloc()/calloc() to g_malloc()/g_try_malloc()/g_new0() Harmandeep Kaur
2015-09-30 19:19 ` Stefan Hajnoczi
2015-10-01  2:56   ` Harmandeep Kaur
2015-10-01 15:51 ` Eric Blake [this message]

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=560D568A.5090005@redhat.com \
    --to=eblake@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    --cc=stefanha@gmail.com \
    --cc=write.harmandeep@gmail.com \
    /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).