From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhg97-0005t0-38 for qemu-devel@nongnu.org; Thu, 01 Oct 2015 11:51:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zhg92-0006i2-3h for qemu-devel@nongnu.org; Thu, 01 Oct 2015 11:51:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zhg91-0006hr-Qj for qemu-devel@nongnu.org; Thu, 01 Oct 2015 11:51:44 -0400 References: From: Eric Blake Message-ID: <560D568A.5090005@redhat.com> Date: Thu, 1 Oct 2015 09:51:38 -0600 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="q95109i4ilBSgVHwPGqv8CLLq9Kvew1bm" Subject: Re: [Qemu-devel] [PATCH] linux-user/syscall.c: malloc()/calloc() to g_malloc()/g_try_malloc()/g_new0() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Harmandeep Kaur , qemu-devel@nongnu.org Cc: Stefan Hajnoczi , riku.voipio@iki.fi This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --q95109i4ilBSgVHwPGqv8CLLq9Kvew1bm Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 >=20 > Signed-off-by: Harmandeep Kaur > --- > linux-user/syscall.c | 36 ++++++++++-------------------------- > 1 file changed, 10 insertions(+), 26 deletions(-) >=20 > 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: > } >=20 > fprog.len =3D tswap16(tfprog->len); > - filter =3D malloc(fprog.len * sizeof(*filter)); > - if (filter =3D=3D NULL) { > - unlock_user_struct(tfilter, tfprog->filter, 1); > - unlock_user_struct(tfprog, optval_addr, 1); > - return -TARGET_ENOMEM; > - } > + filter =3D 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_ >=20 > nsems =3D semid_ds.sem_nsems; >=20 > - *host_array =3D malloc(nsems*sizeof(unsigned short)); > - if (!*host_array) { > - return -TARGET_ENOMEM; > - } > + *host_array =3D 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, >=20 > if (!lock_user_struct(VERIFY_READ, target_mb, msgp, 0)) > return -TARGET_EFAULT; > - host_mb =3D malloc(msgsz+sizeof(long)); > - if (!host_mb) { > - unlock_user_struct(target_mb, msgp, 0); > - return -TARGET_ENOMEM; > - } > + host_mb =3D g_malloc(msgsz+sizeof(long)); As long as you are touching this, spaces around binary + would be nice. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --q95109i4ilBSgVHwPGqv8CLLq9Kvew1bm Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWDVaKAAoJEKeha0olJ0NqMwEH/25cvOFIipPea8BoXyhIETBt shN6sTr+Vuv0Qu9JmxzaHjL+jqHOt60O7NodTPZtk52ZrcrMtglevJp3K9QyYkon EmNcMvmXDOWpTy941C6+UTvex1PgG2n0Emd/JGkiCv24DIcqk63El3BeAS6tzfda zn/miIza4bY4IrNZB0ldr1vQpegaCC4Ud/JYp/zLXt0/MSZom/sX5rEn+WUWLCtW 56fbSjRWPZJGeaFT+zmFcX/gwxcNuMhC4d0ZtMTabCdrY7QHbraRzsl6EHovBS1c Z0uspN6is3DzVlUhgdFye5Iziuw1r8yrBh3QZ241m5Dl+0wkzv0NGWldu7z/jrU= =gT6C -----END PGP SIGNATURE----- --q95109i4ilBSgVHwPGqv8CLLq9Kvew1bm--