[Top][All Lists]

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

Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently

From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
Date: Fri, 29 May 2009 05:53:38 -0500
User-agent: Thunderbird (X11/20090409)

malc wrote:
> On Fri, 29 May 2009, Anthony Liguori wrote:
> Dereference of NULL is UB[1] and dereferencing result of malloc(1) will
> just plain work.

So let's ignoring returning NULL as a possibility..

>> Putting the abort() in there is going to introduce a ton of subtle bugs,
>> I vote for changing qemu_malloc() to have a sane behavior.
> And those will be caught, given one a chance to analyze things, unlike
> head in the sand approach of hoping things would just work.
> After doing some research, after the aforementioned lengthy discussion,
> the only free OS that straight-forwardly described what it does was
> OpenBSD:
> http://www.openbsd.org/cgi-bin/man.cgi?query=malloc&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html
> P.S. So far the abort that went into qemu_malloc caught one usage of zero
>      allocation (once again coming from qcow2).'

But the zero allocation isn't a bug if we return malloc(1).  This is a
common convention and while it may not be portable to every platform's
underlying malloc, we can make this convention portable with qemu_malloc().

At the end of the day, the result is a harder to misuse qemu_malloc()
and that's a very good thing.  I don't want a user to "discover" a
non-portable use of malloc() while trying to do something important.


Anthony Liguori

reply via email to

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