From nobody Sun Feb 8 13:11:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1630788415; cv=none; d=zohomail.com; s=zohoarc; b=bXAKxyZSLHFPlTNyPZ+TD+h7/y5cBZ7nnbRQTbvw4/Ge6LMI+80YMY2TBiWLY09W59im3niZIj4TJTv9e0g6X0XjPcNanMh3PKcMgkB6K/VtS8yXDU5NrsKsCMIaFk5ge5jHvKorwDr7EPqstfvLO1n1KN/AlBYRhTq944mmi0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1630788415; 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=6Au7ZapnY4cI6ZEzODEtc86diDiaHbSisBfMY3NKJhc=; b=c9iQoBEwlKa+JKgp3gJs6SDXu3gU98yqh4idl9/CNfScExkYgouYY5/gSV7CBS5m4Q4F1ITXqT8PiIiESKfXrYahdFzTKuYRQ6xsVS1qW55JkrTQSwxOUEKrY2Lc/+lc9E2laLzU1NPb56+nE2p2RnZ58Ofc6+I6vraq6Y8BLF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1630788415881123.73309610488195; Sat, 4 Sep 2021 13:46:55 -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-412-OFgfTe7dPN6PJ_kDvu8Llw-1; Sat, 04 Sep 2021 16:46:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9AF791006711; Sat, 4 Sep 2021 20:46:47 +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 CCAEC6A910; Sat, 4 Sep 2021 20:46:46 +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 9E8E744A5D; Sat, 4 Sep 2021 20:46:46 +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 184KiaKc008795 for ; Sat, 4 Sep 2021 16:44:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 04CFA2635E; Sat, 4 Sep 2021 20:44:36 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5D0151F4 for ; Sat, 4 Sep 2021 20:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1630788414; 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=6Au7ZapnY4cI6ZEzODEtc86diDiaHbSisBfMY3NKJhc=; b=eMGVst1EbU45SE/grL01LPihGoLdWDro6LaXWNk97vyr9jqG5TSWidVfAX3hFNx58Ke254 87M3zjMdhwQ3qeHWqM06Z42rltS+h4Ry/Bu3rh7SQxMBFSu4pFu4fLIbvaGK2XzTOPj0QV k2YyJmY3aRkWwcbK0PPgEXB08onU3g0= X-MC-Unique: OFgfTe7dPN6PJ_kDvu8Llw-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 10/24] tests: vir: use g_autofree Date: Sat, 4 Sep 2021 22:44:08 +0200 Message-Id: <27693afdd2c7ec6a8bea994247aa606a61eca334.1630788206.git.jtomko@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.15 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1630788416632100001 Signed-off-by: J=C3=A1n Tomko --- tests/vircgrouptest.c | 3 +-- tests/virconftest.c | 6 ++---- tests/vircryptotest.c | 12 ++++-------- tests/virfilecachetest.c | 3 +-- tests/virfilemock.c | 3 +-- tests/virfiletest.c | 6 ++---- tests/virhostcputest.c | 23 +++++++---------------- tests/viriscsitest.c | 3 +-- tests/virkmodtest.c | 9 +++------ tests/virmacmaptest.c | 12 ++++-------- tests/virnetdaemontest.c | 12 ++++-------- tests/virnetsockettest.c | 6 ++---- tests/virnetworkportxml2xmltest.c | 8 ++------ tests/virnumamock.c | 7 ++----- tests/virnwfilterbindingxml2xmltest.c | 7 ++----- tests/virpcitest.c | 16 +++++----------- tests/virresctrltest.c | 12 ++++-------- tests/virscsitest.c | 13 ++++--------- tests/virstringtest.c | 12 ++++-------- tests/virsystemdtest.c | 9 +++------ tests/virtestmock.c | 10 +++------- tests/viruritest.c | 3 +-- tests/virusbmock.c | 7 ++----- tests/virusbtest.c | 3 +-- 24 files changed, 65 insertions(+), 140 deletions(-) diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index 1060f6073e..7d54df1a85 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -174,7 +174,7 @@ testCgroupDetectMounts(const void *args) { int result =3D -1; const struct _detectMountsData *data =3D args; - char *parsed =3D NULL; + g_autofree char *parsed =3D NULL; const char *actual; g_autoptr(virCgroup) group =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; @@ -209,7 +209,6 @@ testCgroupDetectMounts(const void *args) =20 cleanup: g_unsetenv("VIR_CGROUP_MOCK_FILENAME"); - VIR_FREE(parsed); return result; } =20 diff --git a/tests/virconftest.c b/tests/virconftest.c index f1a58b01cf..a7189579d3 100644 --- a/tests/virconftest.c +++ b/tests/virconftest.c @@ -70,7 +70,7 @@ static int testConfMemoryNoNewline(const void *opaque G_G= NUC_UNUSED) int ret =3D -1; virConfValue *val; unsigned long long llvalue; - char *str =3D NULL; + g_autofree char *str =3D NULL; int uintvalue; =20 if (!conf) @@ -119,7 +119,6 @@ static int testConfMemoryNoNewline(const void *opaque G= _GNUC_UNUSED) =20 ret =3D 0; cleanup: - VIR_FREE(str); return ret; } =20 @@ -341,7 +340,7 @@ static int testConfParseString(const void *opaque G_GNU= C_UNUSED) =20 int ret =3D -1; g_autoptr(virConf) conf =3D virConfReadString(srcdata, 0); - char *str =3D NULL; + g_autofree char *str =3D NULL; =20 if (!conf) return -1; @@ -367,7 +366,6 @@ static int testConfParseString(const void *opaque G_GNU= C_UNUSED) =20 ret =3D 0; cleanup: - VIR_FREE(str); return ret; } =20 diff --git a/tests/vircryptotest.c b/tests/vircryptotest.c index 2c3d4bfe75..2d503a439e 100644 --- a/tests/vircryptotest.c +++ b/tests/vircryptotest.c @@ -37,7 +37,7 @@ static int testCryptoHash(const void *opaque) { const struct testCryptoHashData *data =3D opaque; - char *actual =3D NULL; + g_autofree char *actual =3D NULL; int ret =3D -1; =20 if (virCryptoHashString(data->hash, data->input, &actual) < 0) { @@ -53,7 +53,6 @@ testCryptoHash(const void *opaque) =20 ret =3D 0; cleanup: - VIR_FREE(actual); return ret; } =20 @@ -70,11 +69,11 @@ static int testCryptoEncrypt(const void *opaque) { const struct testCryptoEncryptData *data =3D opaque; - uint8_t *enckey =3D NULL; + g_autofree uint8_t *enckey =3D NULL; size_t enckeylen =3D 32; - uint8_t *iv =3D NULL; + g_autofree uint8_t *iv =3D NULL; size_t ivlen =3D 16; - uint8_t *ciphertext =3D NULL; + g_autofree uint8_t *ciphertext =3D NULL; size_t ciphertextlen =3D 0; int ret =3D -1; =20 @@ -110,9 +109,6 @@ testCryptoEncrypt(const void *opaque) =20 ret =3D 0; cleanup: - VIR_FREE(enckey); - VIR_FREE(iv); - VIR_FREE(ciphertext); =20 return ret; } diff --git a/tests/virfilecachetest.c b/tests/virfilecachetest.c index 3083aee35d..5730e23b73 100644 --- a/tests/virfilecachetest.c +++ b/tests/virfilecachetest.c @@ -112,14 +112,13 @@ testFileCacheLoadFile(const char *filename, bool *outdated G_GNUC_UNUSED) { testFileCacheObj *obj; - char *data; + g_autofree char *data =3D NULL; =20 if (virFileReadAll(filename, 20, &data) < 0) return NULL; =20 obj =3D testFileCacheObjNew(data); =20 - VIR_FREE(data); return obj; } =20 diff --git a/tests/virfilemock.c b/tests/virfilemock.c index bf153ab769..d4863bd12c 100644 --- a/tests/virfilemock.c +++ b/tests/virfilemock.c @@ -105,7 +105,7 @@ statfs_mock(const char *mtab, FILE *f; struct mntent mb; char mntbuf[1024]; - char *canonPath =3D NULL; + g_autofree char *canonPath =3D NULL; int ret =3D -1; =20 if (!(f =3D real_setmntent(mtab, "r"))) { @@ -158,7 +158,6 @@ statfs_mock(const char *mtab, } =20 endmntent(f); - VIR_FREE(canonPath); return ret; } =20 diff --git a/tests/virfiletest.c b/tests/virfiletest.c index 3c1f2ce54e..019c230cea 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -104,7 +104,7 @@ testFileSanitizePath(const void *opaque) { const struct testFileSanitizePathData *data =3D opaque; int ret =3D -1; - char *actual; + g_autofree char *actual =3D NULL; =20 if (!(actual =3D virFileSanitizePath(data->path))) return -1; @@ -117,7 +117,6 @@ testFileSanitizePath(const void *opaque) ret =3D 0; =20 cleanup: - VIR_FREE(actual); return ret; } =20 @@ -322,7 +321,7 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) return EXIT_AM_SKIP; #else const struct testFileIsSharedFSType *data =3D opaque; - char *mtabFile =3D NULL; + g_autofree char *mtabFile =3D NULL; bool actual; int ret =3D -1; =20 @@ -343,7 +342,6 @@ testFileIsSharedFSType(const void *opaque G_GNUC_UNUSED) =20 ret =3D 0; cleanup: - VIR_FREE(mtabFile); g_unsetenv("LIBVIRT_MTAB"); return ret; #endif diff --git a/tests/virhostcputest.c b/tests/virhostcputest.c index 9e329b38b4..f935df0f63 100644 --- a/tests/virhostcputest.c +++ b/tests/virhostcputest.c @@ -31,7 +31,7 @@ linuxTestCompareFiles(const char *cpuinfofile, const char *outputfile) { int ret =3D -1; - char *actualData =3D NULL; + g_autofree char *actualData =3D NULL; virNodeInfo nodeinfo; FILE *cpuinfo; =20 @@ -68,7 +68,6 @@ linuxTestCompareFiles(const char *cpuinfofile, ret =3D 0; =20 fail: - VIR_FREE(actualData); return ret; } =20 @@ -109,7 +108,7 @@ linuxCPUStatsCompareFiles(const char *cpustatfile, const char *outfile) { int ret =3D -1; - char *actualData =3D NULL; + g_autofree char *actualData =3D NULL; FILE *cpustat =3D NULL; virNodeCPUStatsPtr params =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; @@ -150,7 +149,6 @@ linuxCPUStatsCompareFiles(const char *cpustatfile, =20 fail: VIR_FORCE_FCLOSE(cpustat); - VIR_FREE(actualData); VIR_FREE(params); return ret; } @@ -165,9 +163,9 @@ static int linuxTestHostCPU(const void *opaque) { int result =3D -1; - char *cpuinfo =3D NULL; - char *sysfs_prefix =3D NULL; - char *output =3D NULL; + g_autofree char *cpuinfo =3D NULL; + g_autofree char *sysfs_prefix =3D NULL; + g_autofree char *output =3D NULL; struct linuxTestHostCPUData *data =3D (struct linuxTestHostCPUData *) = opaque; const char *archStr =3D virArchToString(data->arch); =20 @@ -182,10 +180,6 @@ linuxTestHostCPU(const void *opaque) result =3D linuxTestCompareFiles(cpuinfo, data->arch, output); virFileWrapperRemovePrefix(SYSFS_SYSTEM_PATH); =20 - VIR_FREE(cpuinfo); - VIR_FREE(output); - VIR_FREE(sysfs_prefix); - return result; } =20 @@ -232,8 +226,8 @@ linuxTestNodeCPUStats(const void *data) { const struct nodeCPUStatsData *testData =3D data; int result =3D -1; - char *cpustatfile =3D NULL; - char *outfile =3D NULL; + g_autofree char *cpustatfile =3D NULL; + g_autofree g_autofree char *outfile =3D NULL; =20 cpustatfile =3D g_strdup_printf("%s/virhostcpudata/linux-cpustat-%s.st= at", abs_srcdir, testData->name); @@ -255,9 +249,6 @@ linuxTestNodeCPUStats(const void *data) } } =20 - - VIR_FREE(cpustatfile); - VIR_FREE(outfile); return result; } =20 diff --git a/tests/viriscsitest.c b/tests/viriscsitest.c index 37922ba552..7ea761fda6 100644 --- a/tests/viriscsitest.c +++ b/tests/viriscsitest.c @@ -210,7 +210,7 @@ testISCSIGetSession(const void *data) { const struct testSessionInfo *info =3D data; struct testIscsiadmCbData cbData =3D { 0 }; - char *actual_session =3D NULL; + g_autofree char *actual_session =3D NULL; int ret =3D -1; g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); =20 @@ -231,7 +231,6 @@ testISCSIGetSession(const void *data) ret =3D 0; =20 cleanup: - VIR_FREE(actual_session); return ret; } =20 diff --git a/tests/virkmodtest.c b/tests/virkmodtest.c index 2a85e0ae6d..2f07757c88 100644 --- a/tests/virkmodtest.c +++ b/tests/virkmodtest.c @@ -35,7 +35,7 @@ static int checkOutput(virBuffer *buf, const char *exp_cmd) { int ret =3D -1; - char *actual_cmd =3D NULL; + g_autofree char *actual_cmd =3D NULL; =20 if (!(actual_cmd =3D virBufferContentAndReset(buf))) { fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd); @@ -50,7 +50,6 @@ checkOutput(virBuffer *buf, const char *exp_cmd) ret =3D 0; =20 cleanup: - VIR_FREE(actual_cmd); return ret; } =20 @@ -59,7 +58,7 @@ static int testKModLoad(const void *args G_GNUC_UNUSED) { int ret =3D -1; - char *errbuf =3D NULL; + g_autofree char *errbuf =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); =20 @@ -77,7 +76,6 @@ testKModLoad(const void *args G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - VIR_FREE(errbuf); return ret; } =20 @@ -86,7 +84,7 @@ static int testKModUnload(const void *args G_GNUC_UNUSED) { int ret =3D -1; - char *errbuf =3D NULL; + g_autofree char *errbuf =3D NULL; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autoptr(virCommandDryRunToken) dryRunToken =3D virCommandDryRunToken= New(); =20 @@ -104,7 +102,6 @@ testKModUnload(const void *args G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - VIR_FREE(errbuf); return ret; } =20 diff --git a/tests/virmacmaptest.c b/tests/virmacmaptest.c index 4e78615029..01a3588ed9 100644 --- a/tests/virmacmaptest.c +++ b/tests/virmacmaptest.c @@ -39,7 +39,7 @@ testMACLookup(const void *opaque) GSList *macs; GSList *next; size_t i, j; - char *file =3D NULL; + g_autofree char *file =3D NULL; int ret =3D -1; =20 file =3D g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, d= ata->file); @@ -78,7 +78,6 @@ testMACLookup(const void *opaque) =20 ret =3D 0; cleanup: - VIR_FREE(file); return ret; } =20 @@ -90,7 +89,7 @@ testMACRemove(const void *opaque) g_autoptr(virMacMap) mgr =3D NULL; GSList *macs; size_t i; - char *file =3D NULL; + g_autofree char *file =3D NULL; int ret =3D -1; =20 file =3D g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, d= ata->file); @@ -115,7 +114,6 @@ testMACRemove(const void *opaque) =20 ret =3D 0; cleanup: - VIR_FREE(file); return ret; } =20 @@ -124,8 +122,8 @@ static int testMACFlush(const void *opaque) { const struct testData *data =3D opaque; - char *file =3D NULL; - char *str =3D NULL; + g_autofree char *file =3D NULL; + g_autofree char *str =3D NULL; int ret =3D -1; =20 file =3D g_strdup_printf("%s/virmacmaptestdata/%s.json", abs_srcdir, d= ata->file); @@ -138,8 +136,6 @@ testMACFlush(const void *opaque) =20 ret =3D 0; cleanup: - VIR_FREE(file); - VIR_FREE(str); return ret; } =20 diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c index f764268c50..2522a4c8ea 100644 --- a/tests/virnetdaemontest.c +++ b/tests/virnetdaemontest.c @@ -270,10 +270,10 @@ static int testExecRestart(const void *opaque) int ret =3D -1; virNetDaemon *dmn =3D NULL; const struct testExecRestartData *data =3D opaque; - char *infile =3D NULL; - char *outfile =3D NULL; - char *injsonstr =3D NULL; - char *outjsonstr =3D NULL; + g_autofree char *infile =3D NULL; + g_autofree char *outfile =3D NULL; + g_autofree char *injsonstr =3D NULL; + g_autofree char *outjsonstr =3D NULL; virJSONValue *injson =3D NULL; virJSONValue *outjson =3D NULL; int fdclient[2] =3D { -1, -1 }, fdserver[2] =3D { -1, -1 }; @@ -352,10 +352,6 @@ static int testExecRestart(const void *opaque) VIR_TEST_DEBUG("Test should have failed"); ret =3D -1; } - VIR_FREE(infile); - VIR_FREE(outfile); - VIR_FREE(injsonstr); - VIR_FREE(outjsonstr); virJSONValueFree(injson); virJSONValueFree(outjson); virObjectUnref(dmn); diff --git a/tests/virnetsockettest.c b/tests/virnetsockettest.c index 8059c6cbb0..8fbbea5d30 100644 --- a/tests/virnetsockettest.c +++ b/tests/virnetsockettest.c @@ -186,7 +186,7 @@ testSocketAccept(const void *opaque) int ret =3D -1; char portstr[100]; char *tmpdir =3D NULL; - char *path =3D NULL; + g_autofree char *path =3D NULL; char template[] =3D "/tmp/libvirt_XXXXXX"; virThread th; struct testClientData cdata =3D { 0 }; @@ -296,7 +296,6 @@ testSocketAccept(const void *opaque) virObjectUnref(lsock[i]); } VIR_FREE(lsock); - VIR_FREE(path); if (tmpdir) rmdir(tmpdir); return ret; @@ -312,7 +311,7 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_= UNUSED) virNetSocket *csock =3D NULL; /* Client socket */ int ret =3D -1; =20 - char *path =3D NULL; + g_autofree char *path =3D NULL; char *tmpdir; char template[] =3D "/tmp/libvirt_XXXXXX"; =20 @@ -383,7 +382,6 @@ static int testSocketUNIXAddrs(const void *data G_GNUC_= UNUSED) ret =3D 0; =20 cleanup: - VIR_FREE(path); virObjectUnref(lsock); virObjectUnref(ssock); virObjectUnref(csock); diff --git a/tests/virnetworkportxml2xmltest.c b/tests/virnetworkportxml2xm= ltest.c index 039da96490..8d29db724f 100644 --- a/tests/virnetworkportxml2xmltest.c +++ b/tests/virnetworkportxml2xmltest.c @@ -36,7 +36,7 @@ static int testCompareXMLToXMLFiles(const char *expected) { - char *actual =3D NULL; + g_autofree char *actual =3D NULL; int ret =3D -1; g_autoptr(virNetworkPortDef) dev =3D NULL; =20 @@ -51,7 +51,6 @@ testCompareXMLToXMLFiles(const char *expected) =20 ret =3D 0; cleanup: - VIR_FREE(actual); return ret; } =20 @@ -64,15 +63,12 @@ testCompareXMLToXMLHelper(const void *data) { const struct testInfo *info =3D data; int ret =3D -1; - char *xml =3D NULL; + g_autofree char *xml =3D NULL; =20 xml =3D g_strdup_printf("%s/virnetworkportxml2xmldata/%s.xml", abs_src= dir, info->name); =20 ret =3D testCompareXMLToXMLFiles(xml); - - VIR_FREE(xml); - return ret; } =20 diff --git a/tests/virnumamock.c b/tests/virnumamock.c index ff9c6e951d..6e0293a49e 100644 --- a/tests/virnumamock.c +++ b/tests/virnumamock.c @@ -41,13 +41,11 @@ bool virNumaIsAvailable(void) { if (numa_avail < 0) { - char *sysfs_node_path =3D NULL; + g_autofree char *sysfs_node_path =3D NULL; =20 sysfs_node_path =3D g_strdup_printf("%s/node", SYSFS_SYSTEM_PATH); =20 numa_avail =3D virFileExists(sysfs_node_path); - - VIR_FREE(sysfs_node_path); } =20 /* @@ -165,7 +163,7 @@ int virNumaGetNodeCPUs(int node, virBitmap **cpus) { int ret =3D -1; - char *cpulist =3D NULL; + g_autofree char *cpulist =3D NULL; =20 if (virFileReadValueString(&cpulist, "%s/node/node%u/cpulist", @@ -183,6 +181,5 @@ virNumaGetNodeCPUs(int node, virBitmap **cpus) =20 ret =3D virBitmapCountBits(*cpus); cleanup: - VIR_FREE(cpulist); return ret; } diff --git a/tests/virnwfilterbindingxml2xmltest.c b/tests/virnwfilterbindi= ngxml2xmltest.c index ba8edcfd05..ccdad3daa5 100644 --- a/tests/virnwfilterbindingxml2xmltest.c +++ b/tests/virnwfilterbindingxml2xmltest.c @@ -38,7 +38,7 @@ static int testCompareXMLToXMLFiles(const char *xml) { - char *actual =3D NULL; + g_autofree char *actual =3D NULL; int ret =3D -1; virNWFilterBindingDef *dev =3D NULL; =20 @@ -56,7 +56,6 @@ testCompareXMLToXMLFiles(const char *xml) ret =3D 0; =20 fail: - VIR_FREE(actual); virNWFilterBindingDefFree(dev); return ret; } @@ -70,15 +69,13 @@ testCompareXMLToXMLHelper(const void *data) { int result =3D -1; const test_parms *tp =3D data; - char *xml =3D NULL; + g_autofree char *xml =3D NULL; =20 xml =3D g_strdup_printf("%s/virnwfilterbindingxml2xmldata/%s.xml", abs= _srcdir, tp->name); =20 result =3D testCompareXMLToXMLFiles(xml); =20 - VIR_FREE(xml); - return result; } =20 diff --git a/tests/virpcitest.c b/tests/virpcitest.c index 1cffe6e279..1ff0330b22 100644 --- a/tests/virpcitest.c +++ b/tests/virpcitest.c @@ -32,8 +32,8 @@ static int testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char *expected) { - char *path =3D NULL; - char *driver =3D NULL; + g_autofree char *path =3D NULL; + g_autofree char *driver =3D NULL; int ret =3D -1; =20 if (virPCIDeviceGetDriverPathAndName(dev, &path, &driver) < 0) @@ -49,8 +49,6 @@ testVirPCIDeviceCheckDriver(virPCIDevice *dev, const char= *expected) =20 ret =3D 0; cleanup: - VIR_FREE(path); - VIR_FREE(driver); return ret; } =20 @@ -339,7 +337,7 @@ static int mymain(void) { int ret =3D 0; - char *fakerootdir; + g_autofree char *fakerootdir =3D NULL; =20 fakerootdir =3D g_strdup(FAKEROOTDIRTEMPLATE); =20 @@ -361,12 +359,11 @@ mymain(void) struct testPCIDevData data =3D { \ domain, bus, slot, function, NULL \ }; \ - char *label =3D NULL; \ + g_autofree char *label =3D NULL; \ label =3D g_strdup_printf("%s(%04x:%02x:%02x.%x)", \ #fnc, domain, bus, slot, function); \ if (virTestRun(label, fnc, &data) < 0) \ ret =3D -1; \ - VIR_FREE(label); \ } while (0) =20 # define DO_TEST_PCI_DRIVER(domain, bus, slot, function, driver) \ @@ -374,14 +371,13 @@ mymain(void) struct testPCIDevData data =3D { \ domain, bus, slot, function, driver \ }; \ - char *label =3D NULL; \ + g_autofree char *label =3D NULL; \ label =3D g_strdup_printf("PCI driver %04x:%02x:%02x.%x is %s", \ domain, bus, slot, function, \ NULLSTR(driver)); \ if (virTestRun(label, testVirPCIDeviceCheckDriverTest, \ &data) < 0) \ ret =3D -1; \ - VIR_FREE(label); \ } while (0) =20 /* Changes made to individual devices are persistent and the @@ -419,8 +415,6 @@ mymain(void) if (getenv("LIBVIRT_SKIP_CLEANUP") =3D=3D NULL) virFileDeleteTree(fakerootdir); =20 - VIR_FREE(fakerootdir); - return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } =20 diff --git a/tests/virresctrltest.c b/tests/virresctrltest.c index b1dbf66d41..0beb9a4df4 100644 --- a/tests/virresctrltest.c +++ b/tests/virresctrltest.c @@ -18,12 +18,12 @@ static int test_virResctrlGetUnused(const void *opaque) { struct virResctrlData *data =3D (struct virResctrlData *) opaque; - char *system_dir =3D NULL; - char *resctrl_dir =3D NULL; + g_autofree char *system_dir =3D NULL; + g_autofree char *resctrl_dir =3D NULL; int ret =3D -1; g_autoptr(virResctrlAlloc) alloc =3D NULL; - char *schemata_str =3D NULL; - char *schemata_file; + g_autofree char *schemata_str =3D NULL; + g_autofree char *schemata_file =3D NULL; g_autoptr(virCaps) caps =3D NULL; =20 system_dir =3D g_strdup_printf("%s/vircaps2xmldata/linux-%s/system", a= bs_srcdir, @@ -65,10 +65,6 @@ test_virResctrlGetUnused(const void *opaque) =20 ret =3D 0; cleanup: - VIR_FREE(system_dir); - VIR_FREE(resctrl_dir); - VIR_FREE(schemata_str); - VIR_FREE(schemata_file); return ret; } =20 diff --git a/tests/virscsitest.c b/tests/virscsitest.c index 1b6a7b9ae9..d67cd23896 100644 --- a/tests/virscsitest.c +++ b/tests/virscsitest.c @@ -36,7 +36,7 @@ static char *virscsi_prefix; static int test1(const void *data G_GNUC_UNUSED) { - char *name =3D NULL; + g_autofree char *name =3D NULL; int ret =3D -1; =20 if (!(name =3D virSCSIDeviceGetDevName(virscsi_prefix, @@ -48,7 +48,6 @@ test1(const void *data G_GNUC_UNUSED) =20 ret =3D 0; cleanup: - VIR_FREE(name); return ret; } =20 @@ -66,7 +65,7 @@ test2(const void *data G_GNUC_UNUSED) bool free_dev =3D true; bool free_dev1 =3D true; virSCSIDevice *tmp =3D NULL; - char *sgname =3D NULL; + g_autofree char *sgname =3D NULL; int ret =3D -1; =20 sgname =3D virSCSIDeviceGetSgName(virscsi_prefix, @@ -152,7 +151,6 @@ test2(const void *data G_GNUC_UNUSED) =20 ret =3D 0; cleanup: - VIR_FREE(sgname); if (free_dev) virSCSIDeviceFree(dev); if (free_dev1) @@ -164,8 +162,8 @@ static int create_symlink(const char *tmpdir, const char *src_name, const char *dst_n= ame) { int ret =3D -1; - char *src_path =3D NULL; - char *dst_path =3D NULL; + g_autofree char *src_path =3D NULL; + g_autofree char *dst_path =3D NULL; =20 src_path =3D g_strdup_printf("%s/%s", virscsi_prefix, src_name); =20 @@ -179,9 +177,6 @@ create_symlink(const char *tmpdir, const char *src_name= , const char *dst_name) ret =3D 0; =20 cleanup: - VIR_FREE(src_path); - VIR_FREE(dst_path); - return ret; } =20 diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 83b883524d..bbdd17da84 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -222,7 +222,7 @@ static int testStringReplace(const void *opaque G_GNUC_UNUSED) { const struct stringReplaceData *data =3D opaque; - char *result; + g_autofree char *result =3D NULL; int ret =3D -1; =20 result =3D virStringReplace(data->haystack, @@ -238,7 +238,6 @@ testStringReplace(const void *opaque G_GNUC_UNUSED) ret =3D 0; =20 cleanup: - VIR_FREE(result); return ret; } =20 @@ -402,7 +401,7 @@ static int testStripIPv6Brackets(const void *args) { const struct testStripData *data =3D args; int ret =3D -1; - char *res =3D NULL; + g_autofree char *res =3D NULL; =20 res =3D g_strdup(data->string); =20 @@ -417,7 +416,6 @@ static int testStripIPv6Brackets(const void *args) ret =3D 0; =20 cleanup: - VIR_FREE(res); return ret; } =20 @@ -425,7 +423,7 @@ static int testStripControlChars(const void *args) { const struct testStripData *data =3D args; int ret =3D -1; - char *res =3D NULL; + g_autofree char *res =3D NULL; =20 res =3D g_strdup(data->string); =20 @@ -440,7 +438,6 @@ static int testStripControlChars(const void *args) ret =3D 0; =20 cleanup: - VIR_FREE(res); return ret; } =20 @@ -454,7 +451,7 @@ static int testFilterChars(const void *args) { const struct testFilterData *data =3D args; int ret =3D -1; - char *res =3D NULL; + g_autofree char *res =3D NULL; =20 res =3D g_strdup(data->string); =20 @@ -469,7 +466,6 @@ static int testFilterChars(const void *args) ret =3D 0; =20 cleanup: - VIR_FREE(res); return ret; } =20 diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index a09b428a8a..9cf6bfec43 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -325,7 +325,7 @@ static int testCreateNetwork(const void *opaque G_GNUC_= UNUSED) static int testGetMachineName(const void *opaque G_GNUC_UNUSED) { - char *tmp =3D virSystemdGetMachineNameByPID(1234); + g_autofree char *tmp =3D virSystemdGetMachineNameByPID(1234); int ret =3D -1; =20 if (!tmp) { @@ -336,7 +336,6 @@ testGetMachineName(const void *opaque G_GNUC_UNUSED) if (STREQ(tmp, "qemu-demo")) ret =3D 0; =20 - VIR_FREE(tmp); return ret; } =20 @@ -371,7 +370,7 @@ testScopeName(const void *opaque) { const struct testNameData *data =3D opaque; int ret =3D -1; - char *actual =3D NULL; + g_autofree char *actual =3D NULL; =20 if (!(actual =3D virSystemdMakeScopeName(data->name, "lxc", data->lega= cy))) goto cleanup; @@ -385,7 +384,6 @@ testScopeName(const void *opaque) ret =3D 0; =20 cleanup: - VIR_FREE(actual); return ret; } =20 @@ -394,7 +392,7 @@ testMachineName(const void *opaque) { const struct testNameData *data =3D opaque; int ret =3D -1; - char *actual =3D NULL; + g_autofree char *actual =3D NULL; =20 if (!(actual =3D virDomainDriverGenerateMachineName("qemu", data->root, data->id, data->name= , true))) @@ -409,7 +407,6 @@ testMachineName(const void *opaque) ret =3D 0; =20 cleanup: - VIR_FREE(actual); return ret; } =20 diff --git a/tests/virtestmock.c b/tests/virtestmock.c index 0073677b4d..7951f3d00f 100644 --- a/tests/virtestmock.c +++ b/tests/virtestmock.c @@ -100,9 +100,9 @@ static void checkPath(const char *path, const char *func) { - char *fullPath =3D NULL; - char *relPath =3D NULL; - char *crippledPath =3D NULL; + g_autofree char *fullPath =3D NULL; + g_autofree char *relPath =3D NULL; + g_autofree char *crippledPath =3D NULL; =20 if (!g_path_is_absolute(path)) relPath =3D g_strdup_printf("./%s", path); @@ -130,10 +130,6 @@ checkPath(const char *path, printFile(path, func); } =20 - VIR_FREE(crippledPath); - VIR_FREE(relPath); - VIR_FREE(fullPath); - return; } =20 diff --git a/tests/viruritest.c b/tests/viruritest.c index 1962000bc8..96f29aafc0 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -49,7 +49,7 @@ static int testURIParse(const void *args) int ret =3D -1; virURI *uri =3D NULL; const struct URIParseData *data =3D args; - char *uristr =3D NULL; + g_autofree char *uristr =3D NULL; size_t i; bool fail =3D false; =20 @@ -134,7 +134,6 @@ static int testURIParse(const void *args) =20 ret =3D 0; cleanup: - VIR_FREE(uristr); virURIFree(uri); return ret; } diff --git a/tests/virusbmock.c b/tests/virusbmock.c index 57c9611e54..a1f539b8b1 100644 --- a/tests/virusbmock.c +++ b/tests/virusbmock.c @@ -63,7 +63,7 @@ static char *get_fake_path(const char *real_path) =20 DIR *opendir(const char *name) { - char *path; + g_autofree char *path =3D NULL; DIR* ret; =20 init_syms(); @@ -71,13 +71,12 @@ DIR *opendir(const char *name) path =3D get_fake_path(name); =20 ret =3D realopendir(path); - VIR_FREE(path); return ret; } =20 int open(const char *pathname, int flags, ...) { - char *path; + g_autofree char *path =3D NULL; int ret; va_list ap; mode_t mode =3D 0; @@ -98,7 +97,5 @@ int open(const char *pathname, int flags, ...) } =20 ret =3D realopen(path, flags, mode); - - VIR_FREE(path); return ret; } diff --git a/tests/virusbtest.c b/tests/virusbtest.c index 39a8f1a18e..74333f0105 100644 --- a/tests/virusbtest.c +++ b/tests/virusbtest.c @@ -49,7 +49,7 @@ static int testDeviceFileActor(virUSBDevice *dev, const char *path, void *opaque G_GNUC_UNUSED) { - char *str =3D NULL; + g_autofree char *str =3D NULL; int ret =3D 0; =20 str =3D g_strdup_printf(USB_DEVFS "%03d/%03d", virUSBDeviceGetBus(dev), @@ -61,7 +61,6 @@ static int testDeviceFileActor(virUSBDevice *dev, path, str); ret =3D -1; } - VIR_FREE(str); return ret; } =20 --=20 2.31.1