From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M9xh9-0004Cv-Od for qemu-devel@nongnu.org; Fri, 29 May 2009 04:44:07 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M9xh4-0004Bx-KP for qemu-devel@nongnu.org; Fri, 29 May 2009 04:44:07 -0400 Received: from [199.232.76.173] (port=43780 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M9xh4-0004Bq-Gu for qemu-devel@nongnu.org; Fri, 29 May 2009 04:44:02 -0400 Received: from mx2.redhat.com ([66.187.237.31]:43200) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M9xh3-0003bJ-VT for qemu-devel@nongnu.org; Fri, 29 May 2009 04:44:02 -0400 Message-ID: <4A1F9FFE.3030100@redhat.com> Date: Fri, 29 May 2009 10:42:38 +0200 From: Kevin Wolf MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently References: <200905290758.11551.jcd@tribudubois.net> In-Reply-To: <200905290758.11551.jcd@tribudubois.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jean-Christophe Dubois Cc: qemu-devel@nongnu.org Jean-Christophe Dubois schrieb: > qemu_malloc, qemu_free and friends are not used consistently in the qemu > source code. > > This is a first attempt to use these oveloaded functions consistently all over > the place instead of the default glibc versions. > > Signed-off-by: Jean-Christophe DUBOIS [...] > diff -rNu qemu.org/qemu-io.c qemu/qemu-io.c > --- qemu.org/qemu-io.c 2009-05-16 17:57:27.000000000 +0200 > +++ qemu/qemu-io.c 2009-05-18 23:48:23.000000000 +0200 > @@ -311,14 +311,14 @@ > } > > if (Pflag) { > - void* cmp_buf = malloc(pattern_count); > + void* cmp_buf = qemu_malloc(pattern_count); > memset(cmp_buf, pattern, pattern_count); > if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) { > printf("Pattern verification failed at offset %lld, " > "%d bytes\n", > (long long) offset + pattern_offset, pattern_count); > } > - free(cmp_buf); > + qemu_free(cmp_buf); > } > > if (qflag) > @@ -465,14 +465,14 @@ > } > > if (Pflag) { > - void* cmp_buf = malloc(count); > + void* cmp_buf = qemu_malloc(count); > memset(cmp_buf, pattern, count); > if (memcmp(buf, cmp_buf, count)) { > printf("Pattern verification failed at offset %lld, " > "%d bytes\n", > (long long) offset, count); > } > - free(cmp_buf); > + qemu_free(cmp_buf); > } > > if (qflag) Since recently qemu_malloc behaves differently from malloc with size = 0. This isn't allowed any more with qemu_malloc. So you need to check for pattern_count == 0 and either print an error message or malloc a different size, e.g. 1. I'm sure we don't want qemu-io to abort() in such a case. Or we could start over with a lengthy discussion about fixing qemu_malloc... Kevin