From nobody Mon Feb 9 16:53:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1601624707; cv=none; d=zohomail.com; s=zohoarc; b=HS4a6VpPFUe/f7OSd5wNJYwpaWa6RggnOAfdR2UMZSX8DdARvzdHRS+oGuDE64Bf3wY+BQaLZusqjCnaQb63WPS6e3Tv1lv016Av4oKE6sarBvHaNfLTtqoVJH1cAKl0xbc5FnoOpCIVdcwR+xPfwo2qMM4wcwnKwJm9VyAmn1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601624707; 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; bh=Y7aKjrJL7mkcAF7mNVfKGJqT4rh5uFfwh1v2W3tRIKo=; b=bLcvhREhF9yPhKkn67MPk4xt/csuwS9NmQaygn7XnLc34KKJ6kEk0iVZJBJJtsXDl3SNQbeYkb5dpudfvO0VhRVYd/b4Rjo5macAN0/90/oQoVEwjKfGs10eMHP9NGEG3V0xJhA6rKZ5M0cwTIWO4PGB8JBSdV/E82ioobw8G0w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1601624707288178.59288633895642; Fri, 2 Oct 2020 00:45:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-141-1hLXdw1hOISyvw3h-FSL_g-1; Fri, 02 Oct 2020 03:43:45 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4243F6408E; Fri, 2 Oct 2020 07:43:39 +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 220E35D9E4; Fri, 2 Oct 2020 07:43:39 +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 DE9C51826D2E; Fri, 2 Oct 2020 07:43:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0927hLsQ004153 for ; Fri, 2 Oct 2020 03:43:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9E92019931; Fri, 2 Oct 2020 07:43:21 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF4211992F for ; Fri, 2 Oct 2020 07:43:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601624706; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Y7aKjrJL7mkcAF7mNVfKGJqT4rh5uFfwh1v2W3tRIKo=; b=KlSv+Vn/Sb6A/CpkyiFmAQHlVrAJFSxVko9KhUpqpOY5MDZFyeqyzZrnKQrJXd7sJeksrW IYQZ2zGGQaw7WQJ9pKHIDC3cFFTdNZjraj9f61eQhSo6xXBikDNWuOn9YcqhOB5RfZo3Ce w+/Vv6fRHDEvoGjIm+cNBkCLT+4sVvs= X-MC-Unique: 1hLXdw1hOISyvw3h-FSL_g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/15] virbitmaptest: Use g_auto(free) for cleanup Date: Fri, 2 Oct 2020 09:43:00 +0200 Message-Id: <8b3faaece37dd6c13111187324c95c3295032e36.1601624533.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa --- tests/virbitmaptest.c | 73 ++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 49 deletions(-) diff --git a/tests/virbitmaptest.c b/tests/virbitmaptest.c index 1578cd0612..bfca208a7f 100644 --- a/tests/virbitmaptest.c +++ b/tests/virbitmaptest.c @@ -29,7 +29,7 @@ static int test1(const void *data G_GNUC_UNUSED) { - virBitmapPtr bitmap; + g_autoptr(virBitmap) bitmap =3D NULL; int size; int bit; bool result; @@ -58,7 +58,6 @@ test1(const void *data G_GNUC_UNUSED) ret =3D 0; error: - virBitmapFree(bitmap); return ret; } @@ -85,8 +84,8 @@ static int test2(const void *data G_GNUC_UNUSED) { const char *bitsString1 =3D "1-32,50,88-99,1021-1023"; - char *bitsString2 =3D NULL; - virBitmapPtr bitmap =3D NULL; + g_autofree char *bitsString2 =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; int ret =3D -1; int size =3D 1025; @@ -139,15 +138,13 @@ test2(const void *data G_GNUC_UNUSED) ret =3D 0; error: - virBitmapFree(bitmap); - VIR_FREE(bitsString2); return ret; } static int test3(const void *data G_GNUC_UNUSED) { - virBitmapPtr bitmap =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; int ret =3D -1; int size =3D 5; size_t i; @@ -167,7 +164,6 @@ test3(const void *data G_GNUC_UNUSED) ret =3D 0; error: - virBitmapFree(bitmap); return ret; } @@ -185,7 +181,7 @@ test4(const void *data G_GNUC_UNUSED) 1, 5, 11, 13, 19, 21, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 }; - virBitmapPtr bitmap =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; ssize_t i, j; if (G_N_ELEMENTS(bitsPos) + G_N_ELEMENTS(bitsPosInv) !=3D size) @@ -285,11 +281,9 @@ test4(const void *data G_GNUC_UNUSED) if (virBitmapNextClearBit(bitmap, -1) !=3D -1) goto error; - virBitmapFree(bitmap); return 0; error: - virBitmapFree(bitmap); return -1; } @@ -298,14 +292,14 @@ static int test5(const void *v G_GNUC_UNUSED) { char data[] =3D {0x01, 0x02, 0x00, 0x00, 0x04}; - unsigned char *data2 =3D NULL; + g_autofree unsigned char *data2 =3D NULL; int len2; int bits[] =3D {0, 9, 34}; - virBitmapPtr bitmap; + g_autoptr(virBitmap) bitmap =3D NULL; size_t i; ssize_t j; int ret =3D -1; - char *str =3D NULL; + g_autofree char *str =3D NULL; bitmap =3D virBitmapNewData(data, sizeof(data)); if (!bitmap) @@ -347,9 +341,6 @@ test5(const void *v G_GNUC_UNUSED) ret =3D 0; error: - VIR_FREE(str); - virBitmapFree(bitmap); - VIR_FREE(data2); return ret; } @@ -358,8 +349,8 @@ test5(const void *v G_GNUC_UNUSED) static int test6(const void *v G_GNUC_UNUSED) { - virBitmapPtr bitmap =3D NULL; - char *str =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; + g_autofree char *str =3D NULL; int size =3D 64; int ret =3D -1; @@ -432,15 +423,12 @@ test6(const void *v G_GNUC_UNUSED) ret =3D 0; error: - virBitmapFree(bitmap); - VIR_FREE(str); return ret; } static int test7(const void *v G_GNUC_UNUSED) { - virBitmapPtr bitmap; size_t i; size_t maxBit[] =3D { 1, 8, 31, 32, 63, 64, 95, 96, 127, 128, 159, 160 @@ -448,7 +436,7 @@ test7(const void *v G_GNUC_UNUSED) size_t nmaxBit =3D 12; for (i =3D 0; i < nmaxBit; i++) { - bitmap =3D virBitmapNew(maxBit[i]); + g_autoptr(virBitmap) bitmap =3D virBitmapNew(maxBit[i]); if (!bitmap) goto error; @@ -466,21 +454,18 @@ test7(const void *v G_GNUC_UNUSED) virBitmapClearAll(bitmap); if (!virBitmapIsAllClear(bitmap)) goto error; - - virBitmapFree(bitmap); } return 0; error: - virBitmapFree(bitmap); return -1; } static int test8(const void *v G_GNUC_UNUSED) { - virBitmapPtr bitmap =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; char data[108] =3D {0x00,}; int ret =3D -1; @@ -499,7 +484,6 @@ test8(const void *v G_GNUC_UNUSED) ret =3D 0; cleanup: - virBitmapFree(bitmap); return ret; } @@ -509,7 +493,7 @@ static int test9(const void *opaque G_GNUC_UNUSED) { int ret =3D -1; - virBitmapPtr bitmap =3D NULL; + g_autoptr(virBitmap) bitmap =3D NULL; if (virBitmapParse("100000000", &bitmap, 20) !=3D -1) goto cleanup; @@ -531,7 +515,6 @@ test9(const void *opaque G_GNUC_UNUSED) ret =3D 0; cleanup: - virBitmapFree(bitmap); return ret; } @@ -540,7 +523,10 @@ static int test10(const void *opaque G_GNUC_UNUSED) { int ret =3D -1; - virBitmapPtr b1 =3D NULL, b2 =3D NULL, b3 =3D NULL, b4 =3D NULL; + g_autoptr(virBitmap) b1 =3D NULL; + g_autoptr(virBitmap) b2 =3D NULL; + g_autoptr(virBitmap) b3 =3D NULL; + g_autoptr(virBitmap) b4 =3D NULL; if (virBitmapParseSeparator("0-3,5-8,11-15f16", 'f', &b1, 20) < 0 || virBitmapParse("4,9,10,16-19", &b2, 20) < 0 || @@ -561,10 +547,6 @@ test10(const void *opaque G_GNUC_UNUSED) ret =3D 0; cleanup: - virBitmapFree(b1); - virBitmapFree(b2); - virBitmapFree(b3); - virBitmapFree(b4); return ret; } @@ -578,9 +560,9 @@ static int test11(const void *opaque) { const struct testBinaryOpData *data =3D opaque; - virBitmapPtr amap =3D NULL; - virBitmapPtr bmap =3D NULL; - virBitmapPtr resmap =3D NULL; + g_autoptr(virBitmap) amap =3D NULL; + g_autoptr(virBitmap) bmap =3D NULL; + g_autoptr(virBitmap) resmap =3D NULL; int ret =3D -1; if (virBitmapParse(data->a, &amap, 256) < 0 || @@ -600,9 +582,6 @@ test11(const void *opaque) ret =3D 0; cleanup: - virBitmapFree(amap); - virBitmapFree(bmap); - virBitmapFree(resmap); return ret; } @@ -631,7 +610,7 @@ test11(const void *opaque) static int test12(const void *opaque G_GNUC_UNUSED) { - virBitmapPtr map =3D virBitmapNewEmpty(); + g_autoptr(virBitmap) map =3D virBitmapNewEmpty(); int ret =3D -1; TEST_MAP(0, ""); @@ -661,7 +640,6 @@ test12(const void *opaque G_GNUC_UNUSED) ret =3D 0; cleanup: - virBitmapFree(map); return ret; } @@ -699,9 +677,9 @@ static int test14(const void *opaque) { const struct testBinaryOpData *data =3D opaque; - virBitmapPtr amap =3D NULL; - virBitmapPtr bmap =3D NULL; - virBitmapPtr resmap =3D NULL; + g_autoptr(virBitmap) amap =3D NULL; + g_autoptr(virBitmap) bmap =3D NULL; + g_autoptr(virBitmap) resmap =3D NULL; int ret =3D -1; if (virBitmapParse(data->a, &amap, 256) < 0 || @@ -721,9 +699,6 @@ test14(const void *opaque) ret =3D 0; cleanup: - virBitmapFree(amap); - virBitmapFree(bmap); - virBitmapFree(resmap); return ret; } --=20 2.26.2