All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <aliguori@linux.vnet.ibm.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>,
	qemu-devel@nongnu.org, Avi Kivity <avi@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] Do not abort on qemu_malloc(0) in production builds
Date: Wed, 09 Dec 2009 15:03:34 -0600	[thread overview]
Message-ID: <4B2010A6.5030400@linux.vnet.ibm.com> (raw)
In-Reply-To: <m3iqcgt09f.fsf@crossbow.pond.sub.org>

Markus Armbruster wrote:
> Anthony Liguori <aliguori@us.ibm.com> writes:
>
>   
>> qemu_malloc() does not allow size=0 to be passed in and aborts on this behavior.
>>
>> Unfortunately, there is good reason to believe that within qemu, there are a
>> number of, so far, undetected places that assume size=0 can be safely passed.
>> Since we do not want to abort unnecessarily in production builds, return
>> qemu_malloc(1) whenever the version file indicates that this is a production
>> build.
>>
>> Also introduce --enable-zero-malloc/--disable-zero-malloc to make this behavior
>> overridable.
>>
>> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
>> ---
>>  configure     |   24 +++++++++++++++++++++++-
>>  qemu-malloc.c |   17 +++++++++++++----
>>  2 files changed, 36 insertions(+), 5 deletions(-)
>>
>>     
> [...]
>   
>> diff --git a/qemu-malloc.c b/qemu-malloc.c
>> index 295d185..e82af26 100644
>> --- a/qemu-malloc.c
>> +++ b/qemu-malloc.c
>> @@ -42,21 +42,30 @@ void qemu_free(void *ptr)
>>      free(ptr);
>>  }
>>  
>> +static int allow_zero_malloc(void)
>> +{
>> +#if defined(CONFIG_ZERO_MALLOC)
>> +    return 1;
>> +#else
>> +    return 0;
>> +#endif
>> +}
>> +
>>  void *qemu_malloc(size_t size)
>>  {
>> -    if (!size) {
>> +    if (!size && !allow_zero_malloc()) {
>>          abort();
>>      }
>> -    return oom_check(malloc(size));
>> +    return oom_check(malloc(size ? size : 1));
>>  }
>>  
>>  void *qemu_realloc(void *ptr, size_t size)
>>  {
>>      if (size) {
>>          return oom_check(realloc(ptr, size));
>> -    } else {
>> +    } else if (allow_zero_malloc()) {
>>          if (ptr) {
>> -            return realloc(ptr, size);
>> +            return realloc(ptr, size ? size : 1);
>>          }
>>      }
>>      abort();
>>     
>
> This still aborts on qemu_realloc(NULL, 0), even with
> CONFIG_ZERO_MALLOC.  Intentional?
>   
I guess not.  Should it?  Seems like a very strange case..

Regards,

Anthony Liguori


-- 
Regards,

Anthony Liguori

  reply	other threads:[~2009-12-09 21:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-09 19:04 [Qemu-devel] [PATCH] Do not abort on qemu_malloc(0) in production builds Anthony Liguori
2009-12-09 19:28 ` Markus Armbruster
2009-12-09 21:03   ` Anthony Liguori [this message]
2009-12-09 21:35     ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B2010A6.5030400@linux.vnet.ibm.com \
    --to=aliguori@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=armbru@redhat.com \
    --cc=avi@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.