[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] linux-user/syscall.c: malloc()/calloc() to g_ma
From: |
Eric Blake |
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 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 |
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 <address@hidden>
> ---
> 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
signature.asc
Description: OpenPGP digital signature