From nobody Sun Feb 8 20:35:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.74 as permitted sender) client-ip=63.128.21.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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=1595979692; cv=none; d=zohomail.com; s=zohoarc; b=I+6PkmDqvdEM0TR1ei3QJsp4rGUYkLwftUneSOVpAk9fwBDusip0m9yJlC/YJaGNnnOfjKbOz+nrkKzB/32vY8gzl8nNHEQOwOKFLoaYHkgKHP2xgagu+I7FsAHb+TlG5n78FK4ebV7rG2GyyCDePF4f/rOcJ5MtUfoDWB3TnBQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595979692; 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=ujMrTeVLY5D1pTQXbsJ/pUA2fkZzETUh/HYzXZIJB7g=; b=LJYeXOl7Qnol7L1bqTYz188VOxGgWynjkMxWuXzP6tnYRXnOROl6OPZrGax8Kzl22K5EvttrwPV0T7gPa5YGcmkJOUw48nSfHMJLS60TYd1GLzjXHqenbuNbs6arWP1YJayHnW1aa9P3A2dNRjr8tu9DAvBQyzJzHRHhS2LORDM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.74 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-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by mx.zohomail.com with SMTPS id 1595979692521546.1237352051094; Tue, 28 Jul 2020 16:41:32 -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-250-xYEYOxBAPgq-qKPfUis6-w-1; Tue, 28 Jul 2020 19:41:28 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7BDDA800688; Tue, 28 Jul 2020 23:41:23 +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 5B4A510013C4; Tue, 28 Jul 2020 23:41:23 +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 2B4BF180599D; Tue, 28 Jul 2020 23:41:23 +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 06SNeuq7003864 for ; Tue, 28 Jul 2020 19:40:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAE7D8A160; Tue, 28 Jul 2020 23:40:56 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.40.208.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DC0079251 for ; Tue, 28 Jul 2020 23:40:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595979691; 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=ujMrTeVLY5D1pTQXbsJ/pUA2fkZzETUh/HYzXZIJB7g=; b=WXWReu0W6uotAB/KFqSIs66qnHWoXZHaz8zycCdRpm+YawRc99/UGU0KUEFs+G+t/pQxmG MUW7hkTYUGF2YfrscRjjdPkNKbAbg6kwdF0j6+6MjSbP1eGN/fO6hwBEhiz8jUwC8isLm0 3y4NJOPi74Y/SsH4qLhzWkpP/H93HLI= X-MC-Unique: xYEYOxBAPgq-qKPfUis6-w-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/5] tests: commandtest: use g_autofree Date: Wed, 29 Jul 2020 01:40:45 +0200 Message-Id: <7d375a013187adf13f2361e3519b72cab4192b7c.1595979625.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.84 on 10.5.11.22 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) Signed-off-by: J=C3=A1n Tomko --- tests/commandtest.c | 76 ++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 50 deletions(-) diff --git a/tests/commandtest.c b/tests/commandtest.c index a18100a705..7c6c3ec75d 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -58,10 +58,10 @@ extern char **environ; static int checkoutput(const char *testname) { int ret =3D -1; - char *expectname =3D NULL; - char *expectlog =3D NULL; - char *actualname =3D NULL; - char *actuallog =3D NULL; + g_autofree char *expectname =3D NULL; + g_autofree char *expectlog =3D NULL; + g_autofree char *actualname =3D NULL; + g_autofree char *actuallog =3D NULL; =20 expectname =3D g_strdup_printf("%s/commanddata/%s.log", abs_srcdir, te= stname); actualname =3D g_strdup_printf("%s/commandhelper.log", abs_builddir); @@ -86,10 +86,6 @@ static int checkoutput(const char *testname) cleanup: if (actualname) unlink(actualname); - VIR_FREE(actuallog); - VIR_FREE(actualname); - VIR_FREE(expectlog); - VIR_FREE(expectname); return ret; } =20 @@ -247,7 +243,7 @@ static int test4(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNewArgList(abs_builddir "/commandhelpe= r", "--check-daemonize", NULL); - char *pidfile =3D virPidFileBuildPath(abs_builddir, "commandhelper"); + g_autofree char *pidfile =3D virPidFileBuildPath(abs_builddir, "comman= dhelper"); pid_t pid; int ret =3D -1; =20 @@ -275,7 +271,6 @@ static int test4(const void *unused G_GNUC_UNUSED) virCommandFree(cmd); if (pidfile) unlink(pidfile); - VIR_FREE(pidfile); return ret; } =20 @@ -484,7 +479,7 @@ static int test12(const void *unused G_GNUC_UNUSED) static int test13(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); - char *outactual =3D NULL; + g_autofree char *outactual =3D NULL; const char *outexpect =3D "BEGIN STDOUT\n" "Hello World\n" "END STDOUT\n"; @@ -512,7 +507,6 @@ static int test13(const void *unused G_GNUC_UNUSED) =20 cleanup: virCommandFree(cmd); - VIR_FREE(outactual); return ret; } =20 @@ -523,16 +517,16 @@ static int test13(const void *unused G_GNUC_UNUSED) static int test14(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); - char *outactual =3D NULL; + g_autofree char *outactual =3D NULL; const char *outexpect =3D "BEGIN STDOUT\n" "Hello World\n" "END STDOUT\n"; - char *erractual =3D NULL; + g_autofree char *erractual =3D NULL; const char *errexpect =3D "BEGIN STDERR\n" "Hello World\n" "END STDERR\n"; =20 - char *jointactual =3D NULL; + g_autofree char *jointactual =3D NULL; const char *jointexpect =3D "BEGIN STDOUT\n" "BEGIN STDERR\n" "Hello World\n" @@ -582,9 +576,6 @@ static int test14(const void *unused G_GNUC_UNUSED) =20 cleanup: virCommandFree(cmd); - VIR_FREE(outactual); - VIR_FREE(erractual); - VIR_FREE(jointactual); return ret; } =20 @@ -596,7 +587,7 @@ static int test14(const void *unused G_GNUC_UNUSED) static int test15(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); - char *cwd =3D NULL; + g_autofree char *cwd =3D NULL; int ret =3D -1; =20 cwd =3D g_strdup_printf("%s/commanddata", abs_srcdir); @@ -611,7 +602,6 @@ static int test15(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test15"); =20 cleanup: - VIR_FREE(cwd); virCommandFree(cmd); =20 return ret; @@ -623,7 +613,7 @@ static int test15(const void *unused G_GNUC_UNUSED) static int test16(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew("true"); - char *outactual =3D NULL; + g_autofree char *outactual =3D NULL; const char *outexpect =3D "A=3DB C=3D'D E' true F 'G H'"; int ret =3D -1; int fd =3D -1; @@ -658,7 +648,6 @@ static int test16(const void *unused G_GNUC_UNUSED) cleanup: virCommandFree(cmd); VIR_FORCE_CLOSE(fd); - VIR_FREE(outactual); return ret; } =20 @@ -669,8 +658,8 @@ static int test17(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew("true"); int ret =3D -1; - char *outbuf; - char *errbuf =3D NULL; + char *outbuf =3D NULL; + g_autofree char *errbuf =3D NULL; =20 virCommandSetOutputBuffer(cmd, &outbuf); if (outbuf !=3D NULL) { @@ -711,7 +700,6 @@ static int test17(const void *unused G_GNUC_UNUSED) cleanup: virCommandFree(cmd); VIR_FREE(outbuf); - VIR_FREE(errbuf); return ret; } =20 @@ -721,7 +709,7 @@ static int test17(const void *unused G_GNUC_UNUSED) static int test18(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNewArgList("sleep", "100", NULL); - char *pidfile =3D virPidFileBuildPath(abs_builddir, "commandhelper"); + g_autofree char *pidfile =3D virPidFileBuildPath(abs_builddir, "comman= dhelper"); pid_t pid; int ret =3D -1; =20 @@ -759,7 +747,6 @@ static int test18(const void *unused G_GNUC_UNUSED) virCommandFree(cmd); if (pidfile) unlink(pidfile); - VIR_FREE(pidfile); return ret; } =20 @@ -807,7 +794,7 @@ static int test20(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNewArgList(abs_builddir "/commandhelpe= r", "--close-stdin", NULL); - char *buf; + g_autofree char *buf =3D NULL; int ret =3D -1; =20 struct sigaction sig_action; @@ -829,7 +816,6 @@ static int test20(const void *unused G_GNUC_UNUSED) ret =3D checkoutput("test20"); cleanup: virCommandFree(cmd); - VIR_FREE(buf); return ret; } =20 @@ -850,7 +836,8 @@ static int test21(const void *unused G_GNUC_UNUSED) virCommandPtr cmd =3D virCommandNew(abs_builddir "/commandhelper"); int ret =3D -1; const char *wrbuf =3D "Hello world\n"; - char *outbuf =3D NULL, *errbuf =3D NULL; + g_autofree char *outbuf =3D NULL; + g_autofree char *errbuf =3D NULL; const char *outbufExpected =3D "BEGIN STDOUT\n" "Hello world\n" "END STDOUT\n"; @@ -886,8 +873,6 @@ static int test21(const void *unused G_GNUC_UNUSED) =20 ret =3D checkoutput("test21"); cleanup: - VIR_FREE(outbuf); - VIR_FREE(errbuf); virCommandFree(cmd); return ret; } @@ -1006,7 +991,7 @@ static int test25(const void *unused G_GNUC_UNUSED) int rv =3D 0; ssize_t tries =3D 100; pid_t pid; - gid_t *groups =3D NULL; + g_autofree gid_t *groups =3D NULL; int ngroups; virCommandPtr cmd =3D virCommandNew("some/nonexistent/binary"); =20 @@ -1068,7 +1053,6 @@ static int test25(const void *unused G_GNUC_UNUSED) cleanup: VIR_FORCE_CLOSE(pipeFD[0]); VIR_FORCE_CLOSE(pipeFD[1]); - VIR_FREE(groups); virCommandFree(cmd); return ret; } @@ -1080,7 +1064,7 @@ static int test25(const void *unused G_GNUC_UNUSED) static int test26(const void *unused G_GNUC_UNUSED) { virCommandPtr cmd =3D virCommandNew("true"); - char *outactual =3D NULL; + g_autofree char *outactual =3D NULL; const char *outexpect =3D "A=3DB \\\n" "C=3D'D E' \\\n" @@ -1131,7 +1115,6 @@ static int test26(const void *unused G_GNUC_UNUSED) cleanup: virCommandFree(cmd); VIR_FORCE_CLOSE(fd); - VIR_FREE(outactual); return ret; } =20 @@ -1142,16 +1125,16 @@ static int test27(const void *unused G_GNUC_UNUSED) int pipe2[2]; int ret =3D -1; size_t buflen =3D 1024 * 128; - char *buffer0 =3D NULL; - char *buffer1 =3D NULL; - char *buffer2 =3D NULL; - char *outactual =3D NULL; - char *erractual =3D NULL; - char *outexpect =3D NULL; + g_autofree char *buffer0 =3D NULL; + g_autofree char *buffer1 =3D NULL; + g_autofree char *buffer2 =3D NULL; + g_autofree char *outactual =3D NULL; + g_autofree char *erractual =3D NULL; + g_autofree char *outexpect =3D NULL; # define TEST27_OUTEXPECT_TEMP "BEGIN STDOUT\n" \ "%s%s%s" \ "END STDOUT\n" - char *errexpect =3D NULL; + g_autofree char *errexpect =3D NULL; # define TEST27_ERREXPECT_TEMP "BEGIN STDERR\n" \ "%s%s%s" \ "END STDERR\n" @@ -1235,13 +1218,6 @@ static int test27(const void *unused G_GNUC_UNUSED) VIR_FORCE_CLOSE(pipe2[0]); VIR_FORCE_CLOSE(pipe1[1]); VIR_FORCE_CLOSE(pipe2[1]); - VIR_FREE(buffer0); - VIR_FREE(buffer1); - VIR_FREE(buffer2); - VIR_FREE(outactual); - VIR_FREE(erractual); - VIR_FREE(outexpect); - VIR_FREE(errexpect); =20 return ret; } --=20 2.26.2