From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xcn5h-0000Ts-IV for qemu-devel@nongnu.org; Fri, 10 Oct 2014 23:11:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xcn5c-0002d9-Hz for qemu-devel@nongnu.org; Fri, 10 Oct 2014 23:11:33 -0400 Message-ID: <54389FB1.8040207@huawei.com> Date: Sat, 11 Oct 2014 11:10:41 +0800 From: zhanghailiang MIME-Version: 1.0 References: <1412996048-6384-1-git-send-email-arei.gonglei@huawei.com> In-Reply-To: <1412996048-6384-1-git-send-email-arei.gonglei@huawei.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] oslib-posix: change free to g_free List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: arei.gonglei@huawei.com, qemu-devel@nongnu.org Cc: kwolf@redhat.com, qemu-trivial@nongnu.org, weidong.huang@huawei.com, stefanha@redhat.com, pbonzini@redhat.com On 2014/10/11 10:54, arei.gonglei@huawei.com wrote: > From: Gonglei > > The caller of qemu_vfree() maybe not check whether parameter > ptr pointer is NULL or not, such as vpc_open(). > Using g_free() is more safe. > It seems that free(NULL) is harmless. From section 7.20.3.2/2 of the C99 standard: The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs. > Signed-off-by: Gonglei > --- > util/oslib-posix.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/util/oslib-posix.c b/util/oslib-posix.c > index 016a047..ca435d0 100644 > --- a/util/oslib-posix.c > +++ b/util/oslib-posix.c > @@ -153,7 +153,7 @@ void *qemu_anon_ram_alloc(size_t size) > void qemu_vfree(void *ptr) > { > trace_qemu_vfree(ptr); > - free(ptr); > + g_free(ptr); > } > > void qemu_anon_ram_free(void *ptr, size_t size) >