From nobody Sun Feb 8 16:30:53 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=1569604673; cv=none; d=zoho.com; s=zohoarc; b=GI9n7NLVuCAemzj7PzEGFMLkrE5tdt6slDiwaElgcBOr7BdyZzBjGxHLuw3McqZIxC8RfcufdN7eUBlpWRWyUrZuDFfsyK7UTecKBcEogA9HhzRQd26fktHPiiuvTPM3D7rndQ4KcqBA7jatkj3Th4+s3XHb5QxvDrfeoDFk85E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569604673; 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=Su7zjhjcLTKdX2Xv/OvK723l868M0rWHMc9STpZR4Qw=; b=kHBHZ9ZsiT1zo06YxcOVrPbQ9P9n94X+ubxkSFzxexswiMxlVgndjNNwr2zie9xzIlNurajVRWn04qyKzyhHal8XtRD/pcSuFxzzg0+Ld0Kab9VaR/tlv/9smBSw1twe9uijx/p3wseQWC2XXE3dO4sgxvW1kCplp85G+4/TpV0= 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 1569604673021739.0813916530403; Fri, 27 Sep 2019 10:17:53 -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 1F82B309DEE4; Fri, 27 Sep 2019 17:17:51 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E37DA5D9C3; Fri, 27 Sep 2019 17:17:50 +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 8C69A180085A; Fri, 27 Sep 2019 17:17:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x8RHHiNK016549 for ; Fri, 27 Sep 2019 13:17:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 20719600D1; Fri, 27 Sep 2019 17:17:44 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-55.ams2.redhat.com [10.36.112.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 246F4600C6; Fri, 27 Sep 2019 17:17:42 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Sep 2019 18:17:26 +0100 Message-Id: <20190927171733.10842-5-berrange@redhat.com> In-Reply-To: <20190927171733.10842-1-berrange@redhat.com> References: <20190927171733.10842-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 04/11] util: use glib memory 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.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 27 Sep 2019 17:17:51 +0000 (UTC) Convert the VIR_ALLOC family of APIs with use of the g_malloc family of APIs. Use of VIR_ALLOC related functions should be incrementally phased out over time, allowing return value checks to be dropped. Use of VIR_FREE should be replaced with auto-cleanup whenever possible. We previously used the 'calloc-posix' gnulib module because mingw does not set errno to ENOMEM on failure. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- bootstrap.conf | 1 - src/util/viralloc.c | 29 ++++++----------------------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 4f944a9c23..549d18c6d4 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -28,7 +28,6 @@ byteswap c-ctype c-strcase c-strcasestr -calloc-posix canonicalize-lgpl chown clock-time diff --git a/src/util/viralloc.c b/src/util/viralloc.c index 10a8d0fb73..b8ca850764 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 @@ -343,9 +328,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 @@ -362,7 +345,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; } @@ -395,7 +378,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