[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] block: Simplify a few g_try_malloc() error chec
From: |
Kevin Wolf |
Subject: |
Re: [Qemu-devel] [PATCH] block: Simplify a few g_try_malloc() error checks |
Date: |
Tue, 27 Jan 2015 15:07:07 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
Am 27.01.2015 um 14:42 hat Markus Armbruster geschrieben:
> Paolo Bonzini <address@hidden> writes:
>
> > On 27/01/2015 13:25, Markus Armbruster wrote:
> >> Unlike malloc(), g_try_malloc() & friends return a null pointer only
> >> on failure, never for a zero size. Simplify tests for failure
> >> accordingly. This helps Coverity see returned null pointers can't be
> >> dereferenced. Also makes the code easier to read.
> >
> > Unfortunately that's not what I see from the source:
> >
> > gpointer
> > g_try_malloc (gsize n_bytes)
> > {
> > gpointer mem;
> >
> > if (G_LIKELY (n_bytes))
> > mem = glib_mem_vtable.try_malloc (n_bytes);
> > else
> > mem = NULL;
> >
> > TRACE (GLIB_MEM_ALLOC((void*) mem, (unsigned int) n_bytes, 0, 1));
> >
> > return mem;
> > }
>
> You're right. Brain fart, please ignore.
Should we consider introducing a qemu_try_malloc() that has the desired
behaviour? The (g_try_)malloc() interface is really easy to misuse and
I've messed up some error checks in the block layer myself.
Kevin