qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] Convert uses of malloc to g_malloc


From: Thomas Huth
Subject: Re: [Qemu-devel] [PATCH] Convert uses of malloc to g_malloc
Date: Thu, 29 Sep 2016 19:24:43 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0

On 29.09.2016 18:57, Annapoornima Koppad wrote:
> Signed-off-by: Annapoornima Koppad <address@hidden>
> ---
>  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(-)
> 
> 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;
>      }
>  
> -    acb->task = malloc(sizeof(struct scsi_task));
> +    acb->task = g_malloc(sizeof(struct scsi_task));
>      if (acb->task == 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]