From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NIThz-0002vl-DS for qemu-devel@nongnu.org; Wed, 09 Dec 2009 16:04:27 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NITht-0002uh-Cy for qemu-devel@nongnu.org; Wed, 09 Dec 2009 16:04:26 -0500 Received: from [199.232.76.173] (port=36435 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NITht-0002ue-3X for qemu-devel@nongnu.org; Wed, 09 Dec 2009 16:04:21 -0500 Received: from e5.ny.us.ibm.com ([32.97.182.145]:56561) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NIThs-0006Hl-LO for qemu-devel@nongnu.org; Wed, 09 Dec 2009 16:04:20 -0500 Received: from d01relay03.pok.ibm.com (d01relay03.pok.ibm.com [9.56.227.235]) by e5.ny.us.ibm.com (8.14.3/8.13.1) with ESMTP id nB9KqsGQ003773 for ; Wed, 9 Dec 2009 15:52:54 -0500 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d01relay03.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id nB9L4EPY114046 for ; Wed, 9 Dec 2009 16:04:14 -0500 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.3/8.13.1/NCO v10.0 AVout) with ESMTP id nB9L3bxs005265 for ; Wed, 9 Dec 2009 14:03:37 -0700 Message-ID: <4B2010A6.5030400@linux.vnet.ibm.com> Date: Wed, 09 Dec 2009 15:03:34 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] Do not abort on qemu_malloc(0) in production builds References: <1260385471-8561-1-git-send-email-aliguori@us.ibm.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: Anthony Liguori , qemu-devel@nongnu.org, Avi Kivity Markus Armbruster wrote: > Anthony Liguori 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 >> --- >> 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