From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=45691 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PKoHO-0006sF-8q for qemu-devel@nongnu.org; Tue, 23 Nov 2010 03:31:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PKoHN-00080j-Fx for qemu-devel@nongnu.org; Tue, 23 Nov 2010 03:31:10 -0500 Received: from mail-qy0-f180.google.com ([209.85.216.180]:53788) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PKoHN-00080X-De for qemu-devel@nongnu.org; Tue, 23 Nov 2010 03:31:09 -0500 Received: by qyk29 with SMTP id 29so1964170qyk.4 for ; Tue, 23 Nov 2010 00:31:08 -0800 (PST) Sender: Paolo Bonzini Message-ID: <4CEB7BCA.5030001@redhat.com> Date: Tue, 23 Nov 2010 09:31:06 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: <20101122101536.2B09BF90AF@ochil.suse.de> <4CEB7778.4010900@suse.de> In-Reply-To: <4CEB7778.4010900@suse.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH] scsi: Implement alloc_req_iov callback List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hannes Reinecke Cc: Stefan Hajnoczi , qemu-devel@nongnu.org, nab@linux-iscsi.org, kraxel@redhat.com On 11/23/2010 09:12 AM, Hannes Reinecke wrote: > qemu-malloc.c has: > > void qemu_free(void *ptr) > { > trace_qemu_free(ptr); > free(ptr); > } > > > and 'free' doesn't normally do an error checking on the argument. > Am I missing something? It's not error checking: from free(3), free() frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc(), calloc() or realloc(). Otherwise, or if free(ptr) has already been called before, undefined behavior occurs. If ptr is NULL, no operation is performed. Which means, that unless ptr is so often NULL that there is a measurable overhead from the call (unlikely in any case, not just this one) the "if" is actually going to be done by "free", and thus causing actually worse performance. Not that man pages are always right, but in this case they agree with POSIX. :) Paolo