Received: from eggs.gnu.org ([2001:4830:134:3::10]:43700) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpf4l-0006Vi-9B for qemu-devel@nongnu.org; Thu, 29 Sep 2016 13:24:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpf4h-0004pG-8D for qemu-devel@nongnu.org; Thu, 29 Sep 2016 13:24:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33662) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpf4h-0004oN-1Q for qemu-devel@nongnu.org; Thu, 29 Sep 2016 13:24:47 -0400 References: <1475168226-13194-1-git-send-email-annakoppad@gmail.com> From: Thomas Huth Message-ID: <847ef312-0844-d071-4000-5e4c60cee0ec@redhat.com> Date: Thu, 29 Sep 2016 19:24:43 +0200 MIME-Version: 1.0 In-Reply-To: <1475168226-13194-1-git-send-email-annakoppad@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] Convert uses of malloc to g_malloc List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Annapoornima Koppad , qemu-devel@nongnu.org On 29.09.2016 18:57, Annapoornima Koppad wrote: > Signed-off-by: Annapoornima Koppad > --- > block/iscsi.c | 2 +- > bsd-user/elfload.c | 12 ++++++------ > disas/libvixl/vixl/a64/disasm-a64.cc | 2 +- > disas/m68k.c | 2 +- > disas/sparc.c | 4 ++-- > hw/audio/fmopl.c | 10 +++++----- > hw/usb/redirect.c | 2 +- > include/exec/softmmu-semi.h | 4 ++-- > linux-user/elfload.c | 2 +- > linux-user/syscall.c | 2 +- > slirp/mbuf.c | 4 ++-- > slirp/sbuf.c | 2 +- > slirp/socket.c | 2 +- > slirp/tcp_subr.c | 2 +- > tests/migration/stress.c | 4 ++-- > tests/tcg/cris/check_openpf1.c | 2 +- > tests/tcg/linux-test.c | 4 ++-- > tests/tcg/test-mmap.c | 2 +- > thunk.c | 2 +- > util/compatfd.c | 2 +- > util/envlist.c | 6 +++--- > 21 files changed, 37 insertions(+), 37 deletions(-) >=20 > diff --git a/block/iscsi.c b/block/iscsi.c > index dff548a..21cb41b 100644 > --- a/block/iscsi.c > +++ b/block/iscsi.c > @@ -963,7 +963,7 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState= *bs, > return NULL; > } > =20 > - acb->task =3D malloc(sizeof(struct scsi_task)); > + acb->task =3D g_malloc(sizeof(struct scsi_task)); > if (acb->task =3D=3D NULL) { > error_report("iSCSI: Failed to allocate task for scsi command.= %s", > iscsi_get_error(iscsi)); Sorry, but it's not as simple as only replacing malloc with g_malloc: g_malloc does not return NULL on out-of-memory conditions anymore, but exits immediately. So with g_malloc, you don't need the check for NULL afterwards anymore. You've got to look at the cases more carefully: Is the NULL check exiting or aborting afterwards? Then you can use g_malloc and remove the check for NULL (with the code that exits/aborts). Or is the NULL check rather recovering from the error and continues execution? Then you might need to keep the NULL check block and use g_try_malloc instead. Thomas