From nobody Sun Feb 8 07:08:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1567101792; cv=none; d=zoho.com; s=zohoarc; b=OrCN4UQDi8UgGhmuErT6mDyMQ4to2s8W//wP7P7pxsxVfxq4snpa2o9Dot/ABGAXpXdTxS/ifr/olLTc/LX3CZShl+H5lhek/apH82uS88T1zOriWbiHlFlQwzdZOYvxc+cAsfERbXlcN0ebehtgfnaJo4HfSouzCkvvS/YSrbc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1567101792; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ZB1mtY2buGHcdytJhLbgJmPUko8Rza+gRmzGFqEKunQ=; b=P+w83DqKKoIKQPfoJtfNmWtel6ea/H4PkelGLrb78TQA4eR+OuFN6Tl5wJmuf8/6CKxMXTKiWdsgTOXkGhKa4lRHrk5fFOWGzGxpzZ88OytPRGNLCB51whDWi1EUVd0bQktDT/30qtTgdG37pnt/FBZSxarRl92jAmM9r1IrT7s= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1567101792256211.3937801522369; Thu, 29 Aug 2019 11:03:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B982410F23F2; Thu, 29 Aug 2019 18:03:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 853B15D9D3; Thu, 29 Aug 2019 18:03:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2DC5724F36; Thu, 29 Aug 2019 18:03:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x7TI35vt020501 for ; Thu, 29 Aug 2019 14:03:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 705E46060D; Thu, 29 Aug 2019 18:03:05 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-60.ams2.redhat.com [10.36.112.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1C416061E; Thu, 29 Aug 2019 18:03:04 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 29 Aug 2019 19:02:50 +0100 Message-Id: <20190829180250.3290-8-berrange@redhat.com> In-Reply-To: <20190829180250.3290-1-berrange@redhat.com> References: <20190829180250.3290-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/7] util: use glib allocation functions X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Thu, 29 Aug 2019 18:03:11 +0000 (UTC) GLib requires that any memory allocated with g_new/g_malloc/etc is free'd by g_free. This means mixing virAlloc with g_free, or g_new with virFree will violate API rules. The easy way to dea with this is to simply make our allocation functions wrappers to the glib functions. Use of our allocation functions can be phased out gradually over time. When doing such conversions, the return values checks can be dropped at the same time. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/util/viralloc.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/util/viralloc.c b/src/util/viralloc.c index b74f657733..b50d989415 100644 --- a/src/util/viralloc.c +++ b/src/util/viralloc.c @@ -45,10 +45,7 @@ VIR_LOG_INIT("util.alloc"); int virAlloc(void *ptrptr, size_t size) { - *(void **)ptrptr =3D calloc(1, size); - if (*(void **)ptrptr =3D=3D NULL) - abort(); - + *(void **)ptrptr =3D g_malloc0(size); return 0; } =20 @@ -69,10 +66,7 @@ int virAllocN(void *ptrptr, size_t size, size_t count) { - *(void**)ptrptr =3D calloc(count, size); - if (*(void**)ptrptr =3D=3D NULL) - abort(); - + *(void**)ptrptr =3D g_malloc0_n(count, size); return 0; } =20 @@ -94,16 +88,7 @@ int virReallocN(void *ptrptr, size_t size, size_t count) { - void *tmp; - - if (xalloc_oversized(count, size)) - abort(); - - tmp =3D realloc(*(void**)ptrptr, size * count); - if (!tmp && ((size * count) !=3D 0)) - abort(); - - *(void**)ptrptr =3D tmp; + *(void **)ptrptr =3D g_realloc_n(*(void**)ptrptr, size, count); return 0; } =20 @@ -341,9 +326,7 @@ int virAllocVar(void *ptrptr, abort(); =20 alloc_size =3D struct_size + (element_size * count); - *(void **)ptrptr =3D calloc(1, alloc_size); - if (*(void **)ptrptr =3D=3D NULL) - abort(); + *(void **)ptrptr =3D g_malloc0(alloc_size); return 0; } =20 @@ -360,7 +343,7 @@ void virFree(void *ptrptr) { int save_errno =3D errno; =20 - free(*(void**)ptrptr); + g_free(*(void**)ptrptr); *(void**)ptrptr =3D NULL; errno =3D save_errno; } @@ -393,7 +376,7 @@ void virDispose(void *ptrptr, if (*(void**)ptrptr && count > 0) memset(*(void **)ptrptr, 0, count * element_size); =20 - free(*(void**)ptrptr); + g_free(*(void**)ptrptr); *(void**)ptrptr =3D NULL; =20 if (countptr) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list