From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L3aMQ-0006zr-5E for qemu-devel@nongnu.org; Fri, 21 Nov 2008 13:04:06 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L3aMO-0006yw-GZ for qemu-devel@nongnu.org; Fri, 21 Nov 2008 13:04:05 -0500 Received: from [199.232.76.173] (port=38348 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L3aMO-0006ys-8X for qemu-devel@nongnu.org; Fri, 21 Nov 2008 13:04:04 -0500 Received: from ey-out-1920.google.com ([74.125.78.144]:49719) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L3aMN-0003F9-VW for qemu-devel@nongnu.org; Fri, 21 Nov 2008 13:04:04 -0500 Received: by ey-out-1920.google.com with SMTP id 4so451367eyk.4 for ; Fri, 21 Nov 2008 10:04:02 -0800 (PST) Message-ID: <4926F80D.30401@codemonkey.ws> Date: Fri, 21 Nov 2008 12:03:57 -0600 From: Anthony Liguori MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 2 of 5] [UPDATE] implementing qemu_reallocz References: <4926EAD3.6020507@eu.citrix.com> In-Reply-To: <4926EAD3.6020507@eu.citrix.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Stefano Stabellini wrote: > Adding a qemu_reallocz implementation. > > +void *qemu_reallocz(void *ptr, size_t size) > +{ > + void *res; > + res = realloc(ptr, size); > + if (!res) > + return NULL; > + memset(res, 0, size); > + return res; > +} > + > I think this interface is pretty non-intuitive. My first expectation is that only the grown region would be zero'd, not the whole thing. In general, if you don't care about the old memory, free()/malloc() would be a better combination. You're just doing extra work by using realloc() here. Regards, Anthony Liguori > char *qemu_strdup(const char *str) > { > char *ptr; > > >