From nobody Sun May 5 02:25:35 2024 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=1635776201; cv=none; d=zohomail.com; s=zohoarc; b=MyG0PEJye6br9RzDr6DwFiX//3lp2llN7F6vxUQNITB16T4TYoOVE8x4Z1zRnkP2psH/xL7h32kTT3oJZQZR13UAP/rzVFU7z7niB9ylpAnaan79kSlyiakFKqXHBMh9Fni5yfuTPLoz4Dt2LveCi2vAiQCJmLHJuJ4a+hzIX8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635776201; 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=7ix9rOVC4eZlYNlCfNLJceaMrlCWxtSPT1IIHY7P2fM=; b=gf6ig89UErMFYbp/y0IZy5oF+e+gMvQci56gUS9CSCambCocjrbcdh4GETpoQ5FY4gbMVKXx0sEqX0x6rpHbo9aDPaRW1Jm3eHOuE6RGMob6caeDeFGGh6HdJPsiwsr/+Ro/HNwxULGDC9u/GgSk1YEhvIJtGDlbrFGbv2ZBR6U= 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 1635776201111640.0290132356977; Mon, 1 Nov 2021 07:16:41 -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-258-KKjEAThdPW-f31uO_bisOg-1; Mon, 01 Nov 2021 10:16:38 -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 B6A1B100C660; Mon, 1 Nov 2021 14:16:33 +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 7B04B10016F5; Mon, 1 Nov 2021 14:16:33 +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 D1F334A704; Mon, 1 Nov 2021 14:16:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A1EGTIa023062 for ; Mon, 1 Nov 2021 10:16:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0312D60C17; Mon, 1 Nov 2021 14:16:29 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F71460C0F for ; Mon, 1 Nov 2021 14:16:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635776200; 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=7ix9rOVC4eZlYNlCfNLJceaMrlCWxtSPT1IIHY7P2fM=; b=WC5ODOeCSKu6FuK7+bQpWDVMEzOShfCA/BM4YucUFe/lfcOcdFl/I9InKuVZ9C3fGB48ST eikAggCnS+F9oJIAuuWTZzZwu/3K7GNlgoahrchBKjjZiSnjMLwM4Vakm1WgJ+m6S40k1t 5XmmRywayzd2dL96qLVDaZRr/9FmYYw= X-MC-Unique: KKjEAThdPW-f31uO_bisOg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/7] qemuagenttest: Don't leak virTypedParameter on failure Date: Mon, 1 Nov 2021 15:16:13 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 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) X-ZM-MESSAGEID: 1635776202393100001 Content-Type: text/plain; charset="utf-8" There are two functions (testQemuAgentOSInfo() and testQemuAgentTimezone()) which call virTypedParamsFree() only in successful paths. If an error is met then those parameters would be leaked. Fix this by placing the virTypedParamsFree() calls on better place. Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- tests/qemuagenttest.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index bef6dfd152..cebeb5733e 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -1371,12 +1371,12 @@ testQemuAgentOSInfo(const void *data) VALIDATE_PARAM("os.kernel-release", "7601"); VALIDATE_PARAM("os.kernel-version", "6.1"); VALIDATE_PARAM("os.machine", "x86_64"); - virTypedParamsFree(params, nparams); =20 ret =3D 0; =20 cleanup: qemuMonitorTestFree(test); + virTypedParamsFree(params, nparams); return ret; } =20 @@ -1394,6 +1394,8 @@ testQemuAgentTimezone(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + virTypedParameterPtr params =3D NULL; + int nparams =3D 0; int ret =3D -1; =20 if (!test) @@ -1401,8 +1403,6 @@ testQemuAgentTimezone(const void *data) =20 #define VALIDATE_TIMEZONE(response_, expected_name_, expected_offset_) \ do { \ - virTypedParameterPtr params_ =3D NULL; \ - int nparams_ =3D 0; \ int maxparams_ =3D 0; \ const char *name_ =3D NULL; \ int offset_; \ @@ -1411,15 +1411,18 @@ testQemuAgentTimezone(const void *data) if (qemuMonitorTestAddItem(test, "guest-get-timezone", \ response_) < 0) \ goto cleanup; \ + virTypedParamsFree(params, nparams); \ + params =3D NULL; \ + nparams =3D 0; \ if (qemuAgentGetTimezone(qemuMonitorTestGetAgent(test), \ - ¶ms_, &nparams_, &maxparams_, true) <= 0) \ + ¶ms, &nparams, &maxparams_, true) < 0= ) \ goto cleanup; \ - if (nparams_ !=3D 2) { \ + if (nparams !=3D 2) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ - "Expected 2 params, got %d", nparams_); \ + "Expected 2 params, got %d", nparams); \ goto cleanup; \ } \ - if (virTypedParamsGetString(params_, nparams_, \ + if (virTypedParamsGetString(params, nparams, \ "timezone.name", &name_) < 0) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "missing param '%s'", \ "tiemzone.name"); \ @@ -1430,7 +1433,7 @@ testQemuAgentTimezone(const void *data) "Expected name '%s', got '%s'", expected_name_,= name_); \ goto cleanup; \ } \ - if (virTypedParamsGetInt(params_, nparams_, \ + if (virTypedParamsGetInt(params, nparams, \ "timezone.offset", &offset_) < 0) { \ virReportError(VIR_ERR_INTERNAL_ERROR, "missing param '%s'", \ "tiemzone.offset"); \ @@ -1442,7 +1445,6 @@ testQemuAgentTimezone(const void *data) expected_offset_); \ goto cleanup; \ } \ - virTypedParamsFree(params_, nparams_); \ } while (0) =20 VALIDATE_TIMEZONE(testQemuAgentTimezoneResponse1, "IST", 19800); @@ -1454,6 +1456,7 @@ testQemuAgentTimezone(const void *data) =20 cleanup: qemuMonitorTestFree(test); + virTypedParamsFree(params, nparams); return ret; } static int --=20 2.32.0 From nobody Sun May 5 02:25:35 2024 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=1635776203; cv=none; d=zohomail.com; s=zohoarc; b=JzbdYGh/xdw3febRSDAvFIkpa51NmKajyPLU/cZJsgJPZdNG/XfnkojK1pUusSjmdmPG43nmLHCjUCTRZJiBpuK7TXGLDj8QQnIMRcAd/2PqCmy9IKz3pxRFkCNUcPCO3Yz4U6BfQqYGWAZ3WG/MCMgTin0GqbahjvZCIcxHhzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635776203; 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=flfIuzHG1hA4gPIOOiYO4UrIHahpHHhM2K7YAQhsI1Q=; b=jld3s3EfbL8KnOtb+jZ+eB+7rDQf4/CclXeiNf1LUxsr8x0UzuJimnqF4nYxmyDmObcVTneFAO/14umJcufwMwF650DIbcl8Ow/vkuhes4TlRDpF/wy5U38CuUv3n+J3oMaXitJTfAny4jlJltzUXJzZ5/T+EgKGV2v8YQMPBlQ= 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 1635776203739237.86893581696063; Mon, 1 Nov 2021 07:16:43 -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-410-EV5uUUbNNBS2NVg9zwzzqA-1; Mon, 01 Nov 2021 10:16:39 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5966802B61; Mon, 1 Nov 2021 14:16:33 +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 7C0F85C1CF; Mon, 1 Nov 2021 14:16:33 +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 448861806D04; Mon, 1 Nov 2021 14:16:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A1EGUO9023072 for ; Mon, 1 Nov 2021 10:16:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 21D3360C17; Mon, 1 Nov 2021 14:16:30 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50B7B60C0F for ; Mon, 1 Nov 2021 14:16:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635776202; 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=flfIuzHG1hA4gPIOOiYO4UrIHahpHHhM2K7YAQhsI1Q=; b=K8Ov3o1/meEBoEa15DG6yf2vjb/n26QAdeID9bTNpai+PmQvI8udICBSywYPc/R0+FO0pj 9s3D8y61JlmW/RRntJlh0L1iVK/S324x59+MzxC12ABDi9aspZ05JPirZnAr8yGrg3mc++ ps9Tgg5OisqLlzqxk+nIdWAJAEorpkY= X-MC-Unique: EV5uUUbNNBS2NVg9zwzzqA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/7] Prefer g_auto(GStrv) over g_strfreev() Date: Mon, 1 Nov 2021 15:16:14 +0100 Message-Id: <5383632e85ef2c8208eca3dc23900f62c83548a2.1635776103.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.16 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) X-ZM-MESSAGEID: 1635776204608100004 Content-Type: text/plain; charset="utf-8" There are a few cases where a string list is freed by an explicit call of g_strfreev(), but the same result can be achieved by g_atuo(GStrv). Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- src/bhyve/bhyve_command.c | 3 +-- src/bhyve/bhyve_parse_command.c | 22 +++++----------- src/libxl/libxl_conf.c | 9 +++---- src/libxl/xen_common.c | 18 +++++-------- src/libxl/xen_xl.c | 17 +++--------- src/lxc/lxc_container.c | 4 +-- src/lxc/lxc_native.c | 24 +++++------------ src/qemu/qemu_driver.c | 6 ++--- src/remote/remote_daemon_dispatch.c | 3 +-- src/remote/remote_driver.c | 4 +-- src/storage/storage_backend_rbd.c | 3 +-- src/util/vircgroup.c | 3 +-- src/util/vircgroupv2.c | 4 +-- src/util/virfirmware.c | 6 ++--- src/util/viruri.c | 3 +-- src/vbox/vbox_common.c | 12 +++------ src/vbox/vbox_snapshot_conf.c | 40 ++++++++++------------------- src/vbox/vbox_tmpl.c | 3 +-- src/vz/vz_sdk.c | 3 +-- tests/qemumonitorjsontest.c | 3 +-- tests/vboxsnapshotxmltest.c | 3 +-- tests/virconftest.c | 3 +-- tests/virfiletest.c | 3 +-- tests/virstringtest.c | 3 +-- tools/virsh-host.c | 13 +++------- tools/virt-login-shell-helper.c | 7 +++-- tools/vsh.c | 4 +-- 27 files changed, 71 insertions(+), 155 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index ab9d3026cc..cf858dfcd6 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -833,12 +833,11 @@ virBhyveProcessBuildDestroyCmd(struct _bhyveConn *dri= ver G_GNUC_UNUSED, static void virAppendBootloaderArgs(virCommand *cmd, virDomainDef *def) { - char **blargs; + g_auto(GStrv) blargs =3D NULL; =20 /* XXX: Handle quoted? */ blargs =3D g_strsplit(def->os.bootloaderArgs, " ", 0); virCommandAddArgSet(cmd, (const char * const *)blargs); - g_strfreev(blargs); } =20 static virCommand * diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_comman= d.c index 76dcea6f21..f2c15f3aa5 100644 --- a/src/bhyve/bhyve_parse_command.c +++ b/src/bhyve/bhyve_parse_command.c @@ -127,7 +127,7 @@ bhyveCommandLineToArgv(const char *nativeConfig, const char *start; const char *next; char *line; - char **lines =3D NULL; + g_auto(GStrv) lines =3D NULL; size_t i; size_t line_count =3D 0; size_t lines_alloc =3D 0; @@ -168,7 +168,7 @@ bhyveCommandLineToArgv(const char *nativeConfig, =20 for (i =3D 0; i < line_count; i++) { size_t j; - char **arglist =3D NULL; + g_auto(GStrv) arglist =3D NULL; size_t args_count =3D 0; size_t args_alloc =3D 0; =20 @@ -223,23 +223,17 @@ bhyveCommandLineToArgv(const char *nativeConfig, if (!bhyve_argc) goto error; for (j =3D 0; j < args_count; j++) - _bhyve_argv[j] =3D arglist[j]; + _bhyve_argv[j] =3D g_steal_pointer(&arglist[j]); _bhyve_argv[j] =3D NULL; *bhyve_argc =3D args_count-1; - VIR_FREE(arglist); } else if (!_loader_argv) { VIR_REALLOC_N(_loader_argv, args_count + 1); if (!loader_argc) goto error; for (j =3D 0; j < args_count; j++) - _loader_argv[j] =3D arglist[j]; + _loader_argv[j] =3D g_steal_pointer(&arglist[j]); _loader_argv[j] =3D NULL; *loader_argc =3D args_count-1; - VIR_FREE(arglist); - } else { - /* To prevent a use-after-free here, only free the argument li= st - * when it is definitely not going to be used */ - g_strfreev(arglist); } } =20 @@ -247,13 +241,11 @@ bhyveCommandLineToArgv(const char *nativeConfig, if (!(*bhyve_argv =3D _bhyve_argv)) goto error; =20 - g_strfreev(lines); return 0; =20 error: VIR_FREE(_loader_argv); VIR_FREE(_bhyve_argv); - g_strfreev(lines); return -1; } =20 @@ -944,9 +936,9 @@ bhyveParseCommandLineString(const char* nativeConfig, { virDomainDef *def =3D NULL; int bhyve_argc =3D 0; - char **bhyve_argv =3D NULL; + g_auto(GStrv) bhyve_argv =3D NULL; int loader_argc =3D 0; - char **loader_argv =3D NULL; + g_auto(GStrv) loader_argv =3D NULL; =20 if (!(def =3D virDomainDefNew(xmlopt))) goto cleanup; @@ -982,8 +974,6 @@ bhyveParseCommandLineString(const char* nativeConfig, } =20 cleanup: - g_strfreev(loader_argv); - g_strfreev(bhyve_argv); return def; error: virDomainDefFree(def); diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 9f0739e1fa..f37c228139 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1887,8 +1887,7 @@ int libxlDriverGetDom0MaxmemConf(libxlDriverConfig *cfg, unsigned long long *maxmem) { - char **cmd_tokens =3D NULL; - char **mem_tokens =3D NULL; + g_auto(GStrv) cmd_tokens =3D NULL; size_t i; size_t j; libxl_physinfo physinfo; @@ -1899,6 +1898,8 @@ libxlDriverGetDom0MaxmemConf(libxlDriverConfig *cfg, goto physmem; =20 for (i =3D 0; cmd_tokens[i] !=3D NULL; i++) { + g_auto(GStrv) mem_tokens =3D NULL; + if (!STRPREFIX(cmd_tokens[i], "dom0_mem=3D")) continue; =20 @@ -1934,8 +1935,6 @@ libxlDriverGetDom0MaxmemConf(libxlDriverConfig *cfg, goto cleanup; } } - g_strfreev(mem_tokens); - mem_tokens =3D NULL; } =20 physmem: @@ -1950,8 +1949,6 @@ libxlDriverGetDom0MaxmemConf(libxlDriverConfig *cfg, ret =3D 0; =20 cleanup: - g_strfreev(cmd_tokens); - g_strfreev(mem_tokens); return ret; } =20 diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 87f090f979..32c31d240e 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -1045,7 +1045,7 @@ xenParseVifBridge(virDomainNetDef *net, const char *b= ridge) /* 'bridge' string contains a bridge name and one or more vlan tru= nks */ size_t i; size_t nvlans =3D 0; - char **vlanstr_list =3D g_strsplit(bridge, ":", 0); + g_auto(GStrv) vlanstr_list =3D g_strsplit(bridge, ":", 0); =20 if (!vlanstr_list) return -1; @@ -1058,15 +1058,13 @@ xenParseVifBridge(virDomainNetDef *net, const char = *bridge) net->vlan.tag =3D g_new0(unsigned int, nvlans); =20 for (i =3D 1; i <=3D nvlans; i++) { - if (virStrToLong_ui(vlanstr_list[i], NULL, 10, &tag) < 0) { - g_strfreev(vlanstr_list); + if (virStrToLong_ui(vlanstr_list[i], NULL, 10, &tag) < 0) return -1; - } + net->vlan.tag[i - 1] =3D tag; } net->vlan.nTags =3D nvlans; net->vlan.trunk =3D true; - g_strfreev(vlanstr_list); =20 net->virtPortProfile =3D g_new0(virNetDevVPortProfile, 1); net->virtPortProfile->virtPortType =3D VIR_NETDEV_VPORT_PROFILE_OP= ENVSWITCH; @@ -1201,19 +1199,16 @@ xenParseVif(char *entry, const char *vif_typename) goto cleanup; } if (ip) { - char **ip_list =3D g_strsplit(ip, " ", 0); + g_auto(GStrv) ip_list =3D g_strsplit(ip, " ", 0); size_t i; =20 if (!ip_list) goto cleanup; =20 for (i =3D 0; ip_list[i]; i++) { - if (virDomainNetAppendIPAddress(net, ip_list[i], 0, 0) < 0) { - g_strfreev(ip_list); + if (virDomainNetAppendIPAddress(net, ip_list[i], 0, 0) < 0) goto cleanup; - } } - g_strfreev(ip_list); } =20 if (script && script[0]) @@ -1579,7 +1574,7 @@ char * xenMakeIPList(virNetDevIPInfo *guestIP) { size_t i; - char **address_array; + g_auto(GStrv) address_array =3D NULL; char *ret =3D NULL; =20 address_array =3D g_new0(char *, guestIP->nips + 1); @@ -1592,7 +1587,6 @@ xenMakeIPList(virNetDevIPInfo *guestIP) ret =3D g_strjoinv(" ", address_array); =20 cleanup: - g_strfreev(address_array); return ret; } =20 diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 850786e5c9..05d4abbe81 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -246,8 +246,7 @@ static int xenParseXLCPUID(virConf *conf, virDomainDef *def) { g_autofree char *cpuid_str =3D NULL; - char **cpuid_pairs =3D NULL; - char **name_and_value =3D NULL; + g_auto(GStrv) cpuid_pairs =3D NULL; size_t i; int ret =3D -1; int policy; @@ -283,7 +282,7 @@ xenParseXLCPUID(virConf *conf, virDomainDef *def) } =20 for (i =3D 1; cpuid_pairs[i]; i++) { - name_and_value =3D g_strsplit(cpuid_pairs[i], "=3D", 2); + g_auto(GStrv) name_and_value =3D g_strsplit(cpuid_pairs[i], "=3D",= 2); if (!name_and_value) goto cleanup; if (!name_and_value[0] || !name_and_value[1]) { @@ -313,16 +312,11 @@ xenParseXLCPUID(virConf *conf, virDomainDef *def) xenTranslateCPUFeature(name_and_value[0], = true), policy) < 0) goto cleanup; - - g_strfreev(name_and_value); - name_and_value =3D NULL; } =20 ret =3D 0; =20 cleanup: - g_strfreev(name_and_value); - g_strfreev(cpuid_pairs); return ret; } =20 @@ -406,7 +400,6 @@ xenParseXLVnuma(virConf *conf, { int ret =3D -1; char *tmp =3D NULL; - char **token =3D NULL; size_t vcpus =3D 0; size_t nr_nodes =3D 0; size_t vnodeCnt =3D 0; @@ -506,6 +499,7 @@ xenParseXLVnuma(virConf *conf, vcpus +=3D virBitmapCountBits(cpumask); =20 } else if (STRPREFIX(str, "vdistances")) { + g_auto(GStrv) token =3D NULL; size_t i, ndistances; unsigned int value; =20 @@ -519,7 +513,6 @@ xenParseXLVnuma(virConf *conf, VIR_FREE(tmp); tmp =3D g_strdup(vtoken); =20 - g_strfreev(token); if (!(token =3D g_strsplit(tmp, ",", 0))) goto cleanup; =20 @@ -583,7 +576,6 @@ xenParseXLVnuma(virConf *conf, cleanup: if (ret) VIR_FREE(cpu); - g_strfreev(token); VIR_FREE(tmp); =20 return ret; @@ -1301,7 +1293,7 @@ xenFormatXLOS(virConf *conf, virDomainDef *def) static int xenFormatXLCPUID(virConf *conf, virDomainDef *def) { - char **cpuid_pairs =3D NULL; + g_auto(GStrv) cpuid_pairs =3D NULL; g_autofree char *cpuid_string =3D NULL; size_t i, j; int ret =3D -1; @@ -1359,7 +1351,6 @@ xenFormatXLCPUID(virConf *conf, virDomainDef *def) ret =3D 0; =20 cleanup: - g_strfreev(cpuid_pairs); return ret; } =20 diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index d788e77196..13f2fd4c29 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -510,7 +510,7 @@ extern int pivot_root(const char * new_root, const char= * put_old); static int lxcContainerUnmountSubtree(const char *prefix, bool isOldRootFS) { - char **mounts =3D NULL; + g_auto(GStrv) mounts =3D NULL; size_t nmounts =3D 0; size_t i; int saveErrno; @@ -555,8 +555,6 @@ static int lxcContainerUnmountSubtree(const char *prefi= x, ret =3D 0; =20 cleanup: - g_strfreev(mounts); - return ret; } =20 diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index 3840652912..f3b8e85143 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -107,8 +107,8 @@ static char ** lxcStringSplit(const char *string) g_autofree char *tmp =3D NULL; size_t i; size_t ntokens =3D 0; - char **parts; - char **result =3D NULL; + g_auto(GStrv) parts =3D NULL; + g_auto(GStrv) result =3D NULL; =20 tmp =3D g_strdup(string); =20 @@ -132,12 +132,9 @@ static char ** lxcStringSplit(const char *string) result[ntokens - 2] =3D g_strdup(parts[i]); } =20 - g_strfreev(parts); - return result; + return g_steal_pointer(&result); =20 error: - g_strfreev(parts); - g_strfreev(result); return NULL; } =20 @@ -145,7 +142,7 @@ static lxcFstab * lxcParseFstabLine(char *fstabLine) { lxcFstab *fstab =3D NULL; - char **parts; + g_auto(GStrv) parts =3D NULL; =20 if (!fstabLine) return NULL; @@ -162,13 +159,10 @@ lxcParseFstabLine(char *fstabLine) fstab->type =3D g_strdup(parts[2]); fstab->options =3D g_strdup(parts[3]); =20 - g_strfreev(parts); - return fstab; =20 error: lxcFstabFree(fstab); - g_strfreev(parts); return NULL; } =20 @@ -252,7 +246,7 @@ lxcAddFstabLine(virDomainDef *def, lxcFstab *fstab) { const char *src =3D NULL; g_autofree char *dst =3D NULL; - char **options =3D g_strsplit(fstab->options, ",", 0); + g_auto(GStrv) options =3D g_strsplit(fstab->options, ",", 0); bool readonly; int type =3D VIR_DOMAIN_FS_TYPE_MOUNT; unsigned long long usage =3D 0; @@ -307,7 +301,6 @@ lxcAddFstabLine(virDomainDef *def, lxcFstab *fstab) ret =3D 1; =20 cleanup: - g_strfreev(options); return ret; } =20 @@ -967,7 +960,7 @@ lxcSetCpusetTune(virDomainDef *def, virConf *properties) static int lxcBlkioDeviceWalkCallback(const char *name, virConfValue *value, void *da= ta) { - char **parts =3D NULL; + g_auto(GStrv) parts =3D NULL; virBlkioDevice *device =3D NULL; virDomainDef *def =3D data; size_t i =3D 0; @@ -1044,7 +1037,6 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfV= alue *value, void *data) ret =3D 0; =20 cleanup: - g_strfreev(parts); return ret; } =20 @@ -1072,7 +1064,7 @@ static void lxcSetCapDrop(virDomainDef *def, virConf *properties) { g_autofree char *value =3D NULL; - char **toDrop =3D NULL; + g_auto(GStrv) toDrop =3D NULL; const char *capString; size_t i; =20 @@ -1087,8 +1079,6 @@ lxcSetCapDrop(virDomainDef *def, virConf *properties) } =20 def->features[VIR_DOMAIN_FEATURE_CAPABILITIES] =3D VIR_DOMAIN_CAPABILI= TIES_POLICY_ALLOW; - - g_strfreev(toDrop); } =20 virDomainDef * diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 70b5f37e6b..a12ef2227e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1329,7 +1329,7 @@ qemuGetSchedInfo(unsigned long long *cpuWait, { g_autofree char *proc =3D NULL; g_autofree char *data =3D NULL; - char **lines =3D NULL; + g_auto(GStrv) lines =3D NULL; size_t i; int ret =3D -1; double val; @@ -1392,7 +1392,6 @@ qemuGetSchedInfo(unsigned long long *cpuWait, ret =3D 0; =20 cleanup: - g_strfreev(lines); return ret; } =20 @@ -12517,7 +12516,7 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn, bool migratable; virCPUDef *cpu =3D NULL; char *cpustr =3D NULL; - char **features =3D NULL; + g_auto(GStrv) features =3D NULL; =20 virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL); @@ -12591,7 +12590,6 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn, cleanup: virCPUDefListFree(cpus); virCPUDefFree(cpu); - g_strfreev(features); =20 return cpustr; } diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index bcfeadc2ae..d8fb02a89d 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -5824,7 +5824,7 @@ remoteDispatchConnectGetCPUModelNames(virNetServer *s= erver G_GNUC_UNUSED, remote_connect_get_cpu_model_names_r= et *ret) { int len, rv =3D -1; - char **models =3D NULL; + g_auto(GStrv) models =3D NULL; virConnectPtr conn =3D remoteGetHypervisorConn(client); =20 if (!conn) @@ -5858,7 +5858,6 @@ remoteDispatchConnectGetCPUModelNames(virNetServer *s= erver G_GNUC_UNUSED, cleanup: if (rv < 0) virNetMessageSaveError(rerr); - g_strfreev(models); return rv; } =20 diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 719fcf4297..8f094db68c 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -6266,7 +6266,7 @@ remoteConnectGetCPUModelNames(virConnectPtr conn, { int rv =3D -1; size_t i; - char **retmodels =3D NULL; + g_auto(GStrv) retmodels =3D NULL; remote_connect_get_cpu_model_names_args args; remote_connect_get_cpu_model_names_ret ret; =20 @@ -6307,8 +6307,6 @@ remoteConnectGetCPUModelNames(virConnectPtr conn, rv =3D ret.ret; =20 cleanup: - g_strfreev(retmodels); - xdr_free((xdrproc_t) xdr_remote_connect_get_cpu_model_names_ret, (char= *) &ret); =20 done: diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_rbd.c index 28b4b7fae6..8276ce20ab 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -659,7 +659,7 @@ virStorageBackendRBDRefreshPool(virStoragePoolObj *pool) virStorageBackendRBDState *ptr =3D NULL; struct rados_cluster_stat_t clusterstat; struct rados_pool_stat_t poolstat; - char **names =3D NULL; + g_auto(GStrv) names =3D NULL; size_t i; =20 if (!(ptr =3D virStorageBackendRBDNewState(pool))) @@ -724,7 +724,6 @@ virStorageBackendRBDRefreshPool(virStoragePoolObj *pool) ret =3D 0; =20 cleanup: - g_strfreev(names); virStorageBackendRBDFreeState(&ptr); return ret; } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 37b63a2e2d..6234095827 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -851,7 +851,7 @@ virCgroupAddThread(virCgroup *group, static int virCgroupSetPartitionSuffix(const char *path, char **res) { - char **tokens; + g_auto(GStrv) tokens =3D NULL; size_t i; int ret =3D -1; =20 @@ -887,7 +887,6 @@ virCgroupSetPartitionSuffix(const char *path, char **re= s) ret =3D 0; =20 cleanup: - g_strfreev(tokens); return ret; } =20 diff --git a/src/util/vircgroupv2.c b/src/util/vircgroupv2.c index 8881d3a88a..4c110940cf 100644 --- a/src/util/vircgroupv2.c +++ b/src/util/vircgroupv2.c @@ -264,7 +264,7 @@ virCgroupV2ParseControllersFile(virCgroup *group, int rc; g_autofree char *contStr =3D NULL; g_autofree char *contFile =3D NULL; - char **contList =3D NULL; + g_auto(GStrv) contList =3D NULL; char **tmp; =20 if (parent) { @@ -300,8 +300,6 @@ virCgroupV2ParseControllersFile(virCgroup *group, tmp++; } =20 - g_strfreev(contList); - return 0; } =20 diff --git a/src/util/virfirmware.c b/src/util/virfirmware.c index 258d13bb73..cc5e315b7a 100644 --- a/src/util/virfirmware.c +++ b/src/util/virfirmware.c @@ -59,7 +59,7 @@ int virFirmwareParse(const char *str, virFirmware *firmware) { int ret =3D -1; - char **token; + g_auto(GStrv) token =3D NULL; =20 if (!(token =3D g_strsplit(str, ":", 0))) goto cleanup; @@ -84,7 +84,6 @@ virFirmwareParse(const char *str, virFirmware *firmware) =20 ret =3D 0; cleanup: - g_strfreev(token); return ret; } =20 @@ -95,7 +94,7 @@ virFirmwareParseList(const char *list, size_t *nfirmwares) { int ret =3D -1; - char **token; + g_auto(GStrv) token =3D NULL; size_t i, j; =20 if (!(token =3D g_strsplit(list, ":", 0))) @@ -126,6 +125,5 @@ virFirmwareParseList(const char *list, =20 ret =3D 0; cleanup: - g_strfreev(token); return ret; } diff --git a/src/util/viruri.c b/src/util/viruri.c index 252e4f598e..3c73188a55 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -349,7 +349,7 @@ int virURIResolveAlias(virConf *conf, const char *alias, char **uri) { int ret =3D -1; - char **aliases =3D NULL; + g_auto(GStrv) aliases =3D NULL; =20 *uri =3D NULL; =20 @@ -358,7 +358,6 @@ virURIResolveAlias(virConf *conf, const char *alias, ch= ar **uri) =20 if (aliases && *aliases) { ret =3D virURIFindAliasMatch(aliases, alias, uri); - g_strfreev(aliases); } else { ret =3D 0; } diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 45e7225ae1..cc90e634a3 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -4559,16 +4559,16 @@ vboxSnapshotRedefine(virDomainPtr dom, char *currentSnapshotXmlFilePath =3D NULL; PRUnichar *machineNameUtf16 =3D NULL; char *machineName =3D NULL; - char **realReadWriteDisksPath =3D NULL; + g_auto(GStrv) realReadWriteDisksPath =3D NULL; int realReadWriteDisksPathSize =3D 0; - char **realReadOnlyDisksPath =3D NULL; + g_auto(GStrv) realReadOnlyDisksPath =3D NULL; int realReadOnlyDisksPathSize =3D 0; virVBoxSnapshotConfSnapshot *newSnapshotPtr =3D NULL; unsigned char snapshotUuid[VIR_UUID_BUFLEN]; virVBoxSnapshotConfHardDisk **hardDiskToOpen =3D NULL; size_t hardDiskToOpenSize =3D 0; virVBoxSnapshotConfHardDisk *newHardDisk =3D NULL; - char **searchResultTab =3D NULL; + g_auto(GStrv) searchResultTab =3D NULL; ssize_t resultSize =3D 0; int it =3D 0; int jt =3D 0; @@ -5371,9 +5371,6 @@ vboxSnapshotRedefine(virDomainPtr dom, VIR_FREE(currentSnapshotXmlFilePath); VBOX_UTF16_FREE(machineNameUtf16); VBOX_UTF8_FREE(machineName); - g_strfreev(realReadOnlyDisksPath); - g_strfreev(realReadWriteDisksPath); - g_strfreev(searchResultTab); virVboxSnapshotConfHardDiskFree(newHardDisk); VIR_FREE(hardDiskToOpen); VIR_FREE(newSnapshotPtr); @@ -6792,7 +6789,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapsho= tPtr snapshot) char *settingsFilepath =3D NULL; virVBoxSnapshotConfMachine *snapshotMachineDesc =3D NULL; int isCurrent =3D -1; - char **searchResultTab =3D NULL; + g_auto(GStrv) searchResultTab =3D NULL; ssize_t resultSize =3D 0; int it =3D 0; PRUnichar *machineNameUtf16 =3D NULL; @@ -7195,7 +7192,6 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapsho= tPtr snapshot) VBOX_RELEASE(machine); VBOX_UTF16_FREE(settingsFilePathUtf16); VBOX_UTF8_FREE(settingsFilepath); - g_strfreev(searchResultTab); VIR_FREE(snapshotMachineDesc); VBOX_UTF16_FREE(machineNameUtf16); VBOX_UTF8_FREE(machineName); diff --git a/src/vbox/vbox_snapshot_conf.c b/src/vbox/vbox_snapshot_conf.c index 65546b785e..5894ee1cac 100644 --- a/src/vbox/vbox_snapshot_conf.c +++ b/src/vbox/vbox_snapshot_conf.c @@ -38,7 +38,7 @@ virVBoxSnapshotConfCreateVBoxSnapshotConfHardDiskPtr(xmlN= odePtr diskNode, virVBoxSnapshotConfHardDisk *hardDisk =3D NULL; xmlNodePtr *nodes =3D NULL; char *uuid =3D NULL; - char **searchTabResult =3D NULL; + g_auto(GStrv) searchTabResult =3D NULL; int resultSize =3D 0; size_t i =3D 0; int result =3D -1; @@ -103,7 +103,6 @@ virVBoxSnapshotConfCreateVBoxSnapshotConfHardDiskPtr(xm= lNodePtr diskNode, VIR_FREE(nodes); VIR_FREE(location); VIR_FREE(tmp); - g_strfreev(searchTabResult); if (result < 0) { virVboxSnapshotConfHardDiskFree(hardDisk); hardDisk =3D NULL; @@ -184,7 +183,7 @@ virVBoxSnapshotConfRetrieveSnapshot(xmlNodePtr snapshot= Node, xmlNodePtr snapshotsNode =3D NULL; xmlNodePtr *nodes =3D NULL; char *uuid =3D NULL; - char **searchTabResult =3D NULL; + g_auto(GStrv) searchTabResult =3D NULL; int resultSize =3D 0; size_t i =3D 0; int result =3D -1; @@ -270,7 +269,6 @@ virVBoxSnapshotConfRetrieveSnapshot(xmlNodePtr snapshot= Node, } VIR_FREE(nodes); VIR_FREE(uuid); - g_strfreev(searchTabResult); return snapshot; } =20 @@ -371,9 +369,9 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node, char *uuid =3D NULL; char *timeStamp =3D NULL; =20 - char **firstRegex =3D NULL; + g_auto(GStrv) firstRegex =3D NULL; int firstRegexResult =3D 0; - char **secondRegex =3D NULL; + g_auto(GStrv) secondRegex =3D NULL; int secondRegexResult =3D 0; =20 uuid =3D g_strdup_printf("{%s}", snapshot->uuid); @@ -450,8 +448,6 @@ virVBoxSnapshotConfSerializeSnapshot(xmlNodePtr node, xmlUnlinkNode(snapshotsNode); xmlFreeNode(snapshotsNode); } - g_strfreev(firstRegex); - g_strfreev(secondRegex); VIR_FREE(uuid); VIR_FREE(timeStamp); return result; @@ -581,7 +577,7 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath, g_autoptr(xmlXPathContext) xPathContext =3D NULL; char *currentStateModifiedString =3D NULL; =20 - char **searchResultTab =3D NULL; + g_auto(GStrv) searchResultTab =3D NULL; ssize_t searchResultSize =3D 0; char *currentSnapshotAttribute =3D NULL; =20 @@ -719,7 +715,6 @@ virVBoxSnapshotConfLoadVboxFile(const char *filePath, =20 VIR_FREE(currentStateModifiedString); VIR_FREE(currentSnapshotAttribute); - g_strfreev(searchResultTab); if (ret < 0) { virVBoxSnapshotConfMachineFree(machineDescription); machineDescription =3D NULL; @@ -963,9 +958,9 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMach= ine *machine, char *currentSnapshot =3D NULL; char *timeStamp =3D NULL; =20 - char **firstRegex =3D NULL; + g_auto(GStrv) firstRegex =3D NULL; int firstRegexResult =3D 0; - char **secondRegex =3D NULL; + g_auto(GStrv) secondRegex =3D NULL; int secondRegexResult =3D 0; =20 if (machine =3D=3D NULL) { @@ -1171,9 +1166,6 @@ virVBoxSnapshotConfSaveVboxFile(virVBoxSnapshotConfMa= chine *machine, xmlUnlinkNode(machineNode); xmlFreeNode(machineNode); =20 - - g_strfreev(firstRegex); - g_strfreev(secondRegex); return ret; } =20 @@ -1216,7 +1208,7 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(cons= t char *filePath, { int result =3D -1; size_t i =3D 0; - char **ret =3D NULL; + g_auto(GStrv) ret =3D NULL; g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) xPathContext =3D NULL; xmlNodePtr *nodes =3D NULL; @@ -1253,15 +1245,12 @@ virVBoxSnapshotConfGetRWDisksPathsFromLibvirtXML(co= nst char *filePath, if (sourceNode) ret[i] =3D virXMLPropString(sourceNode, "file"); } + *rwDisksPath =3D g_steal_pointer(&ret); result =3D 0; =20 cleanup: - if (result < 0) { - g_strfreev(ret); + if (result < 0) nodeSize =3D -1; - } else { - *rwDisksPath =3D ret; - } VIR_FREE(nodes); return nodeSize; } @@ -1277,7 +1266,7 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(cons= t char *filePath, { int result =3D -1; size_t i =3D 0; - char **ret =3D NULL; + g_auto(GStrv) ret =3D NULL; g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) xPathContext =3D NULL; xmlNodePtr *nodes =3D NULL; @@ -1313,15 +1302,12 @@ virVBoxSnapshotConfGetRODisksPathsFromLibvirtXML(co= nst char *filePath, if (sourceNode) ret[i] =3D virXMLPropString(sourceNode, "file"); } + *roDisksPath =3D g_steal_pointer(&ret); result =3D 0; =20 cleanup: - if (result < 0) { - g_strfreev(ret); + if (result < 0) nodeSize =3D -1; - } else { - *roDisksPath =3D ret; - } VIR_FREE(nodes); return nodeSize; } diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 1772a9b70e..7344882bbd 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -1548,7 +1548,7 @@ _vrdeServerGetPorts(struct _vboxDriver *data, IVRDESe= rver *VRDEServer, PRUnichar *VRDEPortsValue =3D NULL; PRInt32 port =3D -1; ssize_t nmatches =3D 0; - char **matches =3D NULL; + g_auto(GStrv) matches =3D NULL; char *portUtf8 =3D NULL; =20 /* get active (effective) port - available only when VM is running and= has @@ -1596,7 +1596,6 @@ _vrdeServerGetPorts(struct _vboxDriver *data, IVRDESe= rver *VRDEServer, } =20 cleanup: - g_strfreev(matches); VBOX_UTF8_FREE(portUtf8); VBOX_UTF16_FREE(VRDEPortsValue); VBOX_UTF16_FREE(VRDEPortsKey); diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 2ba48134b0..1772f75c3e 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -705,7 +705,7 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk, { char *buf =3D NULL; int ret =3D -1; - char **matches =3D NULL; + g_auto(GStrv) matches =3D NULL; virURI *uri =3D NULL; =20 fs->type =3D VIR_DOMAIN_FS_TYPE_FILE; @@ -767,7 +767,6 @@ prlsdkGetFSInfo(PRL_HANDLE prldisk, =20 cleanup: VIR_FREE(buf); - g_strfreev(matches); return ret; } =20 diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index e5ba39cd2f..25a91cdeb3 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1003,7 +1003,7 @@ testQemuMonitorJSONGetDeviceAliases(const void *opaqu= e) const testGenericData *data =3D opaque; virDomainXMLOption *xmlopt =3D data->xmlopt; int ret =3D -1; - char **aliases =3D NULL; + g_auto(GStrv) aliases =3D NULL; const char **alias; const char *expected[] =3D { "virtio-disk25", "video0", "serial0", "ide0-0-0", "usb", NULL }; @@ -1053,7 +1053,6 @@ testQemuMonitorJSONGetDeviceAliases(const void *opaqu= e) } =20 cleanup: - g_strfreev(aliases); return ret; } =20 diff --git a/tests/vboxsnapshotxmltest.c b/tests/vboxsnapshotxmltest.c index da39561456..d69eb3fc24 100644 --- a/tests/vboxsnapshotxmltest.c +++ b/tests/vboxsnapshotxmltest.c @@ -19,7 +19,7 @@ static char * testFilterXML(char *xml) { g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - char **xmlLines =3D NULL; + g_auto(GStrv) xmlLines =3D NULL; char **xmlLine; char *ret =3D NULL; =20 @@ -39,7 +39,6 @@ testFilterXML(char *xml) ret =3D virBufferContentAndReset(&buf); =20 cleanup: - g_strfreev(xmlLines); return ret; } =20 diff --git a/tests/virconftest.c b/tests/virconftest.c index 5d1ad8a612..32d3d8849b 100644 --- a/tests/virconftest.c +++ b/tests/virconftest.c @@ -372,7 +372,7 @@ static int testConfParseStringList(const void *opaque G= _GNUC_UNUSED) =20 int ret =3D -1; g_autoptr(virConf) conf =3D virConfReadString(srcdata, 0); - char **str =3D NULL; + g_auto(GStrv) str =3D NULL; =20 if (!conf) return -1; @@ -423,7 +423,6 @@ static int testConfParseStringList(const void *opaque G= _GNUC_UNUSED) =20 ret =3D 0; cleanup: - g_strfreev(str); return ret; } =20 diff --git a/tests/virfiletest.c b/tests/virfiletest.c index 1434d6b7ba..2fbece8f63 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -65,7 +65,7 @@ struct testFileGetMountSubtreeData { static int testFileGetMountSubtree(const void *opaque) { int ret =3D -1; - char **gotmounts =3D NULL; + g_auto(GStrv) gotmounts =3D NULL; size_t gotnmounts =3D 0; const struct testFileGetMountSubtreeData *data =3D opaque; =20 @@ -88,7 +88,6 @@ static int testFileGetMountSubtree(const void *opaque) data->mounts, data->nmounts); =20 cleanup: - g_strfreev(gotmounts); return ret; } #endif /* ! defined WITH_MNTENT_H && defined WITH_GETMNTENT_R */ diff --git a/tests/virstringtest.c b/tests/virstringtest.c index 277deca934..77fcec5613 100644 --- a/tests/virstringtest.c +++ b/tests/virstringtest.c @@ -127,7 +127,7 @@ static int testStringSearch(const void *opaque) { const struct stringSearchData *data =3D opaque; - char **matches =3D NULL; + g_auto(GStrv) matches =3D NULL; ssize_t nmatches; int ret =3D -1; =20 @@ -174,7 +174,6 @@ testStringSearch(const void *opaque) ret =3D 0; =20 cleanup: - g_strfreev(matches); return ret; } =20 diff --git a/tools/virsh-host.c b/tools/virsh-host.c index 2a84c58be7..f6aa532b40 100644 --- a/tools/virsh-host.c +++ b/tools/virsh-host.c @@ -1059,7 +1059,7 @@ static char ** vshExtractCPUDefXMLs(vshControl *ctl, const char *xmlFile) { - char **cpus =3D NULL; + g_auto(GStrv) cpus =3D NULL; g_autofree char *buffer =3D NULL; g_autofree char *xmlStr =3D NULL; g_autoptr(xmlDoc) xml =3D NULL; @@ -1126,7 +1126,6 @@ vshExtractCPUDefXMLs(vshControl *ctl, return cpus; =20 error: - g_strfreev(cpus); goto cleanup; } =20 @@ -1163,7 +1162,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) const char *from =3D NULL; bool ret =3D false; int result; - char **cpus =3D NULL; + g_auto(GStrv) cpus =3D NULL; unsigned int flags =3D 0; virshControl *priv =3D ctl->privData; =20 @@ -1207,8 +1206,6 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - g_strfreev(cpus); - return ret; } =20 @@ -1585,7 +1582,7 @@ cmdHypervisorCPUCompare(vshControl *ctl, const char *machine =3D NULL; bool ret =3D false; int result; - char **cpus =3D NULL; + g_auto(GStrv) cpus =3D NULL; unsigned int flags =3D 0; virshControl *priv =3D ctl->privData; =20 @@ -1640,7 +1637,6 @@ cmdHypervisorCPUCompare(vshControl *ctl, ret =3D true; =20 cleanup: - g_strfreev(cpus); return ret; } =20 @@ -1699,7 +1695,7 @@ cmdHypervisorCPUBaseline(vshControl *ctl, const char *machine =3D NULL; bool ret =3D false; g_autofree char *result =3D NULL; - char **list =3D NULL; + g_auto(GStrv) list =3D NULL; unsigned int flags =3D 0; virshControl *priv =3D ctl->privData; =20 @@ -1729,7 +1725,6 @@ cmdHypervisorCPUBaseline(vshControl *ctl, ret =3D true; } =20 - g_strfreev(list); return ret; } =20 diff --git a/tools/virt-login-shell-helper.c b/tools/virt-login-shell-helpe= r.c index 5c6e007b09..0fb03da697 100644 --- a/tools/virt-login-shell-helper.c +++ b/tools/virt-login-shell-helper.c @@ -47,7 +47,8 @@ static int virLoginShellAllowedUser(virConf *conf, int ret =3D -1; size_t i; char *gname =3D NULL; - char **users =3D NULL, **entries; + g_auto(GStrv) users =3D NULL; + char **entries; =20 if (virConfGetValueStringList(conf, "allowed_users", false, &users) < = 0) goto cleanup; @@ -84,7 +85,6 @@ static int virLoginShellAllowedUser(virConf *conf, name, conf_file); cleanup: VIR_FREE(gname); - g_strfreev(users); return ret; } =20 @@ -157,7 +157,7 @@ main(int argc, char **argv) uid_t uid; gid_t gid; char *name =3D NULL; - char **shargv =3D NULL; + g_auto(GStrv) shargv =3D NULL; size_t shargvlen =3D 0; char *shcmd =3D NULL; virSecurityModelPtr secmodel =3D NULL; @@ -403,7 +403,6 @@ main(int argc, char **argv) virDomainFree(dom); if (conn) virConnectClose(conn); - g_strfreev(shargv); VIR_FREE(shcmd); VIR_FREE(term); VIR_FREE(name); diff --git a/tools/vsh.c b/tools/vsh.c index ecb591fb63..e3e27a0ba6 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3365,7 +3365,8 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd) int stdin_fileno =3D STDIN_FILENO; const char *arg =3D ""; const vshCmdOpt *opt =3D NULL; - char **matches =3D NULL, **iter; + g_auto(GStrv) matches =3D NULL; + char **iter; g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; =20 if (vshCommandOptStringQuiet(ctl, cmd, "string", &arg) <=3D 0) @@ -3406,7 +3407,6 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - g_strfreev(matches); return ret; } =20 --=20 2.32.0 From nobody Sun May 5 02:25:35 2024 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=1635776283; cv=none; d=zohomail.com; s=zohoarc; b=AXN/LAwe2ulYom6WEsJixUFbR2UnrBT8reNBxtIR3BDLzZYsppG/oUE+BiExFZoAQsQ9fiiFQicoEXKcAI4v66O7DIzGrxdUQ6VeiNsV0pD3kEdh4a9wcZz/aEE5a3hi5b9ILNB+bfFGI/deUy4X6r3CAthDIo0maH7SmQ0R6lA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635776283; 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=sns5DGnhfSrxEzu5b4WRAZV4fJcqqhEqCxOJe29XS7g=; b=FNHVVfqmn2dkbQxxUY9phSjCJ7dFIoOniZ9WYs/PENsfL/kOitfResWUrBNuk1L1kIiKBpvhByISgXWVfGO3bwiFkyAcUzAFbFN+ZKNv/F81I7Rq0hnX0NST7BVpVXNgFyJu3etVXY0VKFV6SpxalRw6xSpLlsdnM88LLHkMQ5Y= 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 1635776283838727.0926309287431; Mon, 1 Nov 2021 07:18:03 -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-138-he5YV94vM06-hxPbWW3cXQ-1; Mon, 01 Nov 2021 10:16:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BEA218125C5; Mon, 1 Nov 2021 14:16:48 +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 3F7366091B; Mon, 1 Nov 2021 14:16:48 +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 0AF4B4EA2A; Mon, 1 Nov 2021 14:16:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A1EGU8r023084 for ; Mon, 1 Nov 2021 10:16:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id E629F60C17; Mon, 1 Nov 2021 14:16:30 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F3DC60C0F for ; Mon, 1 Nov 2021 14:16:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635776282; 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=sns5DGnhfSrxEzu5b4WRAZV4fJcqqhEqCxOJe29XS7g=; b=f/hUZUPqoSCauugLBJAWhA/KlqKqJKi+oKF73FkB9MshhspM9uqFOc2NDbziupwUArARnh RG0Eag2jE3GgurqFOh6J2dOK0vOYY0LJXtoftigLk09EGhFBqjL+/8miYty7iYA12ceAAL I8e0cyLHOccKPwcidI8e4XFBvBiFHgI= X-MC-Unique: he5YV94vM06-hxPbWW3cXQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/7] qemu: Use g_autoptr(qemuMonitorCPUModelInfo) Date: Mon, 1 Nov 2021 15:16:15 +0100 Message-Id: <72e7b1ff640fe176ad08db775bc484964aceb97d.1635776103.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.13 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) X-ZM-MESSAGEID: 1635776285586100001 Content-Type: text/plain; charset="utf-8" There are two instances of an explicit call to qemuMonitorCPUModelInfoFree() which in fact can be turned into g_auto(). Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- src/qemu/qemu_driver.c | 3 +-- tests/qemumonitorjsontest.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a12ef2227e..eac64bce70 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12395,7 +12395,7 @@ static int qemuConnectStealCPUModelFromInfo(virCPUDef *dst, qemuMonitorCPUModelInfo **src) { - qemuMonitorCPUModelInfo *info; + g_autoptr(qemuMonitorCPUModelInfo) info =3D NULL; size_t i; int ret =3D -1; =20 @@ -12418,7 +12418,6 @@ qemuConnectStealCPUModelFromInfo(virCPUDef *dst, ret =3D 0; =20 cleanup: - qemuMonitorCPUModelInfoFree(info); return ret; } =20 diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 25a91cdeb3..bdf557656b 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2839,7 +2839,7 @@ testQemuMonitorJSONqemuMonitorJSONGetCPUModelBaseline= (const void *opaque) g_autoptr(qemuMonitorTest) test =3D NULL; g_autoptr(virCPUDef) cpu_a =3D virCPUDefNew(); g_autoptr(virCPUDef) cpu_b =3D virCPUDefNew(); - qemuMonitorCPUModelInfo *baseline =3D NULL; + g_autoptr(qemuMonitorCPUModelInfo) baseline =3D NULL; int ret =3D -1; =20 if (!(test =3D qemuMonitorTestNewSchema(data->xmlopt, data->schema))) @@ -2898,7 +2898,6 @@ testQemuMonitorJSONqemuMonitorJSONGetCPUModelBaseline= (const void *opaque) ret =3D 0; =20 cleanup: - qemuMonitorCPUModelInfoFree(baseline); return ret; } =20 --=20 2.32.0 From nobody Sun May 5 02:25:35 2024 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=1635776217; cv=none; d=zohomail.com; s=zohoarc; b=kPKTpw0dmBIlDYI0ObhF7IlMrxlSSf0T7dQ7CNYPb9Np55YELNSqaXJHyGDrXSuy9IDiGsINDrc41N69hq8ISZh7FqvOWGXeYrXM5tBFVYVKZnK0T1OsJv4HGyopqNbj41sUaZ1x1AJqrJ9GU2VOZoPefCMN1TVtL9+IDPhphf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635776217; 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=4huTf3CVnTDiiw8zqDfo9kBnAzJrTo0OwCCe/4cMIug=; b=YVlNKDLQo93lw2cKu9hVheqafiMK4I9Fyj/pM6cVGTujQg9MYIgHWoR9Cs0y3UNeqqiY9X7cCXQ8YfXxepzzgQajkMBQ5hgXDWMDxb5clU0BjhCf78CflCNxxJgFEuiRL1CmnWGTqys9XeHjL4luaeNprzHqjlhlfaWzZRcFfgI= 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 1635776217918981.1437663281354; Mon, 1 Nov 2021 07:16:57 -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-396-3Bnrx3u8MZy5-pCUAcFkng-1; Mon, 01 Nov 2021 10:16:55 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F64118125CD; Mon, 1 Nov 2021 14:16:48 +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 565F299C1; Mon, 1 Nov 2021 14:16:48 +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 260A0180BAD2; Mon, 1 Nov 2021 14:16:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A1EGVt1023091 for ; Mon, 1 Nov 2021 10:16:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id B6D3A60C17; Mon, 1 Nov 2021 14:16:31 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F72860C0F for ; Mon, 1 Nov 2021 14:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635776216; 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=4huTf3CVnTDiiw8zqDfo9kBnAzJrTo0OwCCe/4cMIug=; b=AE7pnj0qjFaLqKmQeJDEMZQHEHEbyAwza1Spt+9vwwH2HTHfhUQwoWPOri94OFWPE6Ykoa 3wUomDIZ9PMCPknyf1wyPx9DcCzI/1jNXkLDojfRQ8AwwNsareesnz8ipmnSRBFNqiOlzW pHmurtRly5Bm86M+c7oQuaQUCM05+KU= X-MC-Unique: 3Bnrx3u8MZy5-pCUAcFkng-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/7] qemuConnectStealCPUModelFromInfo: Drop needless 'cleanup' label Date: Mon, 1 Nov 2021 15:16:16 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.23 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) X-ZM-MESSAGEID: 1635776218398100001 Content-Type: text/plain; charset="utf-8" Previous commit rendered 'cleanup' label and @ret variable redundant. The same result can be achieved by returning 0/-1 directly. Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- src/qemu/qemu_driver.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index eac64bce70..4c32d969c7 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12397,7 +12397,6 @@ qemuConnectStealCPUModelFromInfo(virCPUDef *dst, { g_autoptr(qemuMonitorCPUModelInfo) info =3D NULL; size_t i; - int ret =3D -1; =20 virCPUDefFreeModel(dst); =20 @@ -12412,13 +12411,10 @@ qemuConnectStealCPUModelFromInfo(virCPUDef *dst, continue; =20 if (virCPUDefAddFeature(dst, name, VIR_CPU_FEATURE_REQUIRE) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 --=20 2.32.0 From nobody Sun May 5 02:25:35 2024 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=1635776223; cv=none; d=zohomail.com; s=zohoarc; b=UChtf/44l4+k4hFKCCaOURYhZI9/t2n14H7Yo+VIdAQNOFrugSQN8uL3VfGlcViFhamrahoOHXskaH1wnD7V7I0DktMSd07VOETBwxu6EflfD+52gz5sy3zm2QysbpDLYddWksbkqW/sxGaGveLY4E5UtEaHbIG6q34NDYaSnwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635776223; 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=ZIYNl8y5PAr5Ea82fjCVt7k2qQUYLmVC//j1FkRwbx0=; b=iQZg9s8+uFw+fymVxsCpCNnO2Y+uJXTT3hoNAIipuapjQOCCbE6XegirT7XV+pG/c4G+JVf2UhwGH0/6d10aCcptpUQEWEd/0s7CjSLr2H9A7+Fpb5CXNon+ZYnmY+xJCWLk+1mn6nvYrBO8uovhGE1rCHuXwnoiT7jGu/OnAN4= 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) 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 1635776223716618.7945011574989; Mon, 1 Nov 2021 07:17:03 -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-397-qKvC_Ip6NiCf0wNDUyHthA-1; Mon, 01 Nov 2021 10:16:58 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 56A701023F69; Mon, 1 Nov 2021 14:16:51 +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 3199299BD; Mon, 1 Nov 2021 14:16:51 +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 EE9444EA3B; Mon, 1 Nov 2021 14:16:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A1EGWdj023106 for ; Mon, 1 Nov 2021 10:16:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8835460C17; Mon, 1 Nov 2021 14:16:32 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 105FD60C0F for ; Mon, 1 Nov 2021 14:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635776222; 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=ZIYNl8y5PAr5Ea82fjCVt7k2qQUYLmVC//j1FkRwbx0=; b=Q5rCwlr+mKK28gMSaKUeZk+AhzkdOIQu+puFaqwtiWo5/QfPB6gQ4nMQ2wVflFY4Qr6XzH uo0BmILisptjdtP4nP7EPfMYxAUn8lLRvvPLNuNuaZGZeiyGJ4weXQXKx1gHhY3o5LaSAK 383Nwcf8Cl0ski7fOZASsndEY9FDF3s= X-MC-Unique: qKvC_Ip6NiCf0wNDUyHthA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/7] tests: Use g_autoptr(qemuMonitorTest) Date: Mon, 1 Nov 2021 15:16:17 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.23 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) X-ZM-MESSAGEID: 1635776224957100001 Content-Type: text/plain; charset="utf-8" Instead of calling qemuMonitorTestFree() explicitly, we can use g_autoptr() and let it be called automagically. Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- tests/qemuagenttest.c | 46 ++++++++++++------------------------ tests/qemucapabilitiestest.c | 3 +-- tests/qemuhotplugtest.c | 3 +-- tests/qemumigparamstest.c | 6 ++--- tests/qemumonitorjsontest.c | 23 +++++++++--------- tests/qemumonitortestutils.c | 25 ++++++++------------ 6 files changed, 41 insertions(+), 65 deletions(-) diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index cebeb5733e..402c290056 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -109,7 +109,7 @@ static int testQemuAgentFSFreeze(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); const char *mountpoints[] =3D {"/fs1", "/fs2", "/fs3", "/fs4", "/fs5"}; int ret =3D -1; =20 @@ -152,7 +152,6 @@ testQemuAgentFSFreeze(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); return ret; } =20 @@ -161,7 +160,7 @@ static int testQemuAgentFSThaw(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); int ret =3D -1; =20 if (!test) @@ -202,7 +201,6 @@ testQemuAgentFSThaw(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); return ret; } =20 @@ -211,7 +209,7 @@ static int testQemuAgentFSTrim(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); int ret =3D -1; =20 if (!test) @@ -232,7 +230,6 @@ testQemuAgentFSTrim(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); return ret; } =20 @@ -244,7 +241,7 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOption *xmlopt, { int ret =3D -1; g_autofree char *domain_filename =3D NULL; - qemuMonitorTest *ret_test =3D NULL; + g_autoptr(qemuMonitorTest) ret_test =3D NULL; g_autoptr(virDomainDef) ret_def =3D NULL; =20 if (!test || !def) @@ -303,8 +300,6 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOption *xmlopt, ret =3D 0; =20 cleanup: - if (ret_test) - qemuMonitorTestFree(ret_test); return ret; } =20 @@ -312,7 +307,7 @@ static int testQemuAgentGetFSInfo(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D NULL; + g_autoptr(qemuMonitorTest) test =3D NULL; g_autoptr(virDomainDef) def =3D NULL; qemuAgentFSInfo **info =3D NULL; int ret =3D -1, ninfo =3D 0, i; @@ -405,7 +400,6 @@ testQemuAgentGetFSInfo(const void *data) for (i =3D 0; i < ninfo; i++) qemuAgentFSInfoFree(info[i]); VIR_FREE(info); - qemuMonitorTestFree(test); return ret; } =20 @@ -413,7 +407,7 @@ static int testQemuAgentSuspend(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); int ret =3D -1; size_t i; =20 @@ -450,7 +444,6 @@ testQemuAgentSuspend(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); return ret; } =20 @@ -511,7 +504,7 @@ static int testQemuAgentShutdown(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); struct qemuAgentShutdownTestData priv; int ret =3D -1; =20 @@ -590,7 +583,6 @@ testQemuAgentShutdown(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); return ret; } =20 @@ -631,7 +623,7 @@ static int testQemuAgentCPU(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); qemuAgentCPUInfo *cpuinfo =3D NULL; int nvcpus; int ret =3D -1; @@ -703,7 +695,6 @@ testQemuAgentCPU(const void *data) =20 cleanup: VIR_FREE(cpuinfo); - qemuMonitorTestFree(test); return ret; } =20 @@ -715,7 +706,7 @@ static int testQemuAgentArbitraryCommand(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); int ret =3D -1; g_autofree char *reply =3D NULL; =20 @@ -746,7 +737,6 @@ testQemuAgentArbitraryCommand(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); return ret; } =20 @@ -764,7 +754,7 @@ static int testQemuAgentTimeout(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); g_autofree char *reply =3D NULL; int ret =3D -1; =20 @@ -809,7 +799,6 @@ testQemuAgentTimeout(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); return ret; } =20 @@ -890,7 +879,7 @@ static int testQemuAgentGetInterfaces(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); size_t i; int ret =3D -1; int ifaces_count =3D 0; @@ -991,7 +980,6 @@ testQemuAgentGetInterfaces(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); if (ifaces) { for (i =3D 0; i < ifaces_count; i++) virDomainInterfaceFree(ifaces[i]); @@ -1039,7 +1027,7 @@ static int testQemuAgentGetDisks(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); size_t i; int ret =3D -1; int disks_count =3D 0; @@ -1100,7 +1088,6 @@ testQemuAgentGetDisks(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); if (disks) { for (i =3D 0; i < disks_count; i++) qemuAgentDiskInfoFree(disks[i]); @@ -1189,7 +1176,7 @@ static int testQemuAgentUsers(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); virTypedParameterPtr params =3D NULL; int nparams =3D 0; int maxparams =3D 0; @@ -1255,7 +1242,6 @@ testQemuAgentUsers(const void *data) =20 cleanup: virTypedParamsFree(params, nparams); - qemuMonitorTestFree(test); return ret; } =20 @@ -1289,7 +1275,7 @@ static int testQemuAgentOSInfo(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); virTypedParameterPtr params =3D NULL; int nparams =3D 0; int maxparams =3D 0; @@ -1375,7 +1361,6 @@ testQemuAgentOSInfo(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); virTypedParamsFree(params, nparams); return ret; } @@ -1393,7 +1378,7 @@ static int testQemuAgentTimezone(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; - qemuMonitorTest *test =3D qemuMonitorTestNewAgent(xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); virTypedParameterPtr params =3D NULL; int nparams =3D 0; int ret =3D -1; @@ -1455,7 +1440,6 @@ testQemuAgentTimezone(const void *data) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(test); virTypedParamsFree(params, nparams); return ret; } diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index b495bfc07d..b866818e0a 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -72,7 +72,7 @@ testQemuCaps(const void *opaque) testQemuData *data =3D (void *) opaque; g_autofree char *repliesFile =3D NULL; g_autofree char *capsFile =3D NULL; - qemuMonitorTest *mon =3D NULL; + g_autoptr(qemuMonitorTest) mon =3D NULL; g_autoptr(virQEMUCaps) capsActual =3D NULL; g_autofree char *binary =3D NULL; g_autofree char *actual =3D NULL; @@ -132,7 +132,6 @@ testQemuCaps(const void *opaque) =20 ret =3D 0; cleanup: - qemuMonitorTestFree(mon); return ret; } =20 diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index ec448da09e..ac2cf9bb65 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -255,7 +255,7 @@ testQemuHotplug(const void *data) virDomainObj *vm =3D NULL; virDomainDeviceDef *dev =3D NULL; g_autoptr(virCaps) caps =3D NULL; - qemuMonitorTest *test_mon =3D NULL; + g_autoptr(qemuMonitorTest) test_mon =3D NULL; qemuDomainObjPrivate *priv =3D NULL; =20 domain_filename =3D g_strdup_printf("%s/qemuhotplugtestdomains/qemuhot= plug-%s.xml", @@ -359,7 +359,6 @@ testQemuHotplug(const void *data) test->vm =3D NULL; } virDomainDeviceDefFree(dev); - qemuMonitorTestFree(test_mon); return ((ret < 0 && fail) || (!ret && !fail)) ? 0 : -1; } =20 diff --git a/tests/qemumigparamstest.c b/tests/qemumigparamstest.c index 4ab40d9d2e..7d677e2b3a 100644 --- a/tests/qemumigparamstest.c +++ b/tests/qemumigparamstest.c @@ -96,7 +96,7 @@ qemuMigParamsTestXML(const void *opaque) g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autofree char *replyFile =3D NULL; g_autofree char *xmlFile =3D NULL; - qemuMonitorTest *mon =3D NULL; + g_autoptr(qemuMonitorTest) mon =3D NULL; g_autoptr(virJSONValue) params =3D NULL; g_autoptr(qemuMigrationParams) migParams =3D NULL; g_autofree char *actualXML =3D NULL; @@ -128,7 +128,6 @@ qemuMigParamsTestXML(const void *opaque) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(mon); return ret; } =20 @@ -139,7 +138,7 @@ qemuMigParamsTestJSON(const void *opaque) const qemuMigParamsData *data =3D opaque; g_autofree char *replyFile =3D NULL; g_autofree char *jsonFile =3D NULL; - qemuMonitorTest *mon =3D NULL; + g_autoptr(qemuMonitorTest) mon =3D NULL; g_autoptr(virJSONValue) paramsIn =3D NULL; g_autoptr(virJSONValue) paramsOut =3D NULL; g_autoptr(qemuMigrationParams) migParams =3D NULL; @@ -184,7 +183,6 @@ qemuMigParamsTestJSON(const void *opaque) ret =3D 0; =20 cleanup: - qemuMonitorTestFree(mon); return ret; } =20 diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index bdf557656b..e51d6768d5 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -650,10 +650,14 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptio= n *xmlopt, =20 { struct qemuMonitorJSONTestAttachChardevData data =3D {0}; + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewSchema(xmlopt, s= chema); g_autofree char *jsonreply =3D NULL; g_autofree char *fulllabel =3D NULL; int ret =3D -1; =20 + if (!test) + goto cleanup; + if (!reply) reply =3D ""; =20 @@ -661,17 +665,16 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptio= n *xmlopt, =20 fulllabel =3D g_strdup_printf("qemuMonitorJSONTestAttachChardev(%s)", = label); =20 + qemuMonitorTestAllowUnusedCommands(test); + + if (qemuMonitorTestAddItemExpect(test, "chardev-add", + expectargs, true, jsonreply) < 0) + goto cleanup; + data.chr =3D chr; data.fail =3D fail; data.expectPty =3D expectPty; - if (!(data.test =3D qemuMonitorTestNewSchema(xmlopt, schema))) - goto cleanup; - - qemuMonitorTestAllowUnusedCommands(data.test); - - if (qemuMonitorTestAddItemExpect(data.test, "chardev-add", - expectargs, true, jsonreply) < 0) - goto cleanup; + data.test =3D test; =20 if (virTestRun(fulllabel, &testQemuMonitorJSONAttachChardev, &data) < = 0) goto cleanup; @@ -679,7 +682,6 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOption = *xmlopt, ret =3D 0; =20 cleanup: - qemuMonitorTestFree(data.test); return ret; } =20 @@ -2656,7 +2658,7 @@ static int testQueryJobs(const void *opaque) { const struct testQueryJobsData *data =3D opaque; - qemuMonitorTest *test =3D qemuMonitorTestNewSimple(data->xmlopt); + g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewSimple(data->xml= opt); g_autofree char *filenameJSON =3D NULL; g_autofree char *fileJSON =3D NULL; g_autofree char *filenameResult =3D NULL; @@ -2701,7 +2703,6 @@ testQueryJobs(const void *opaque) for (i =3D 0; i < njobs; i++) qemuMonitorJobInfoFree(jobs[i]); VIR_FREE(jobs); - qemuMonitorTestFree(test); return ret; } =20 diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 75a6a76b92..2c63e95bda 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -996,7 +996,7 @@ qemuMonitorCommonTestNew(virDomainXMLOption *xmlopt, virDomainObj *vm, virDomainChrSourceDef *src) { - qemuMonitorTest *test =3D NULL; + g_autoptr(qemuMonitorTest) test =3D NULL; char *path =3D NULL; char *tmpdir_template =3D NULL; =20 @@ -1044,12 +1044,11 @@ qemuMonitorCommonTestNew(virDomainXMLOption *xmlopt, if (virNetSocketListen(test->server, 1) < 0) goto error; =20 - return test; + return g_steal_pointer(&test); =20 error: VIR_FREE(path); VIR_FREE(tmpdir_template); - qemuMonitorTestFree(test); return NULL; =20 } @@ -1116,7 +1115,7 @@ qemuMonitorTestNew(virDomainXMLOption *xmlopt, const char *greeting, GHashTable *schema) { - qemuMonitorTest *test =3D NULL; + g_autoptr(qemuMonitorTest) test =3D NULL; virDomainChrSourceDef src; =20 memset(&src, 0, sizeof(src)); @@ -1150,11 +1149,10 @@ qemuMonitorTestNew(virDomainXMLOption *xmlopt, =20 virDomainChrSourceDefClear(&src); =20 - return test; + return g_steal_pointer(&test); =20 error: virDomainChrSourceDefClear(&src); - qemuMonitorTestFree(test); return NULL; } =20 @@ -1177,7 +1175,7 @@ qemuMonitorTestNewFromFile(const char *fileName, virDomainXMLOption *xmlopt, bool simple) { - qemuMonitorTest *test =3D NULL; + g_autoptr(qemuMonitorTest) test =3D NULL; g_autofree char *json =3D NULL; char *tmp; char *singleReply; @@ -1226,10 +1224,9 @@ qemuMonitorTestNewFromFile(const char *fileName, if (test && qemuMonitorTestAddItem(test, NULL, singleReply) < 0) goto error; =20 - return test; + return g_steal_pointer(&test); =20 error: - qemuMonitorTestFree(test); return NULL; } =20 @@ -1311,7 +1308,7 @@ qemuMonitorTestNewFromFileFull(const char *fileName, virDomainObj *vm, GHashTable *qmpschema) { - qemuMonitorTest *ret =3D NULL; + g_autoptr(qemuMonitorTest) ret =3D NULL; g_autofree char *jsonstr =3D NULL; char *tmp; size_t line =3D 0; @@ -1377,10 +1374,9 @@ qemuMonitorTestNewFromFileFull(const char *fileName, goto error; } =20 - return ret; + return g_steal_pointer(&ret); =20 error: - qemuMonitorTestFree(ret); return NULL; } =20 @@ -1388,7 +1384,7 @@ qemuMonitorTestNewFromFileFull(const char *fileName, qemuMonitorTest * qemuMonitorTestNewAgent(virDomainXMLOption *xmlopt) { - qemuMonitorTest *test =3D NULL; + g_autoptr(qemuMonitorTest) test =3D NULL; virDomainChrSourceDef src; =20 memset(&src, 0, sizeof(src)); @@ -1413,11 +1409,10 @@ qemuMonitorTestNewAgent(virDomainXMLOption *xmlopt) =20 virDomainChrSourceDefClear(&src); =20 - return test; + return g_steal_pointer(&test); =20 error: virDomainChrSourceDefClear(&src); - qemuMonitorTestFree(test); return NULL; } =20 --=20 2.32.0 From nobody Sun May 5 02:25:35 2024 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=1635776219; cv=none; d=zohomail.com; s=zohoarc; b=T3GJKYBfvIopjV+9yLyFxo0c/Q1z9RhixaYY7eCKPz69WqyU7Chn2gkTbOISWoCtmNlKFTuXPwn4HK9AMARJZTNWvJP1deUaWCTTdGF9K6h+rfZAurNLVEKIZj6iqPATa557zDWLV7OrKCaTjlaVCZPWLdvU1wG1pt/DXwenCHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635776219; 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=m7AVCglgKPoe2d1McLbZefDiSgtjsENDMg/2GNrx6oI=; b=Y8nDp0hxGHothvBiGGE/Woj8aUf6dzFJjVRVq6eXEwKkBhXrwLRkWU79nTh4cFWQWRiO4wQPP/nG10bh+bGo0AkSWg+8RBNdo2IYZ9pA7uDI+AjSTyf0lA+AqD/oWENWC+zp17JvswisCUJDxmc5j4q4x5lzXWtNWVzcyNDoGBg= 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 1635776219252674.9101388890308; Mon, 1 Nov 2021 07:16:59 -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-14-X7lw1rwHOBihc1G4Qvmlwg-1; Mon, 01 Nov 2021 10:16:56 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 64574100C662; Mon, 1 Nov 2021 14:16:50 +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 4504F6091B; Mon, 1 Nov 2021 14:16: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 129AB4EA31; Mon, 1 Nov 2021 14:16:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A1EGXKi023111 for ; Mon, 1 Nov 2021 10:16:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 598E560C17; Mon, 1 Nov 2021 14:16:33 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id D598F60C0F for ; Mon, 1 Nov 2021 14:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635776218; 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=m7AVCglgKPoe2d1McLbZefDiSgtjsENDMg/2GNrx6oI=; b=Kxkd8ZPExz87B7OXFfzgy1SWyGfx0k2FNXOdsgSu9+KHgI/et3XFpgDnLMwtcooL2GL+y9 vrAp9NAg3fo+sk0Dxgd+6GhVCjaRkQ5+/FsN8cyF1qcJkW05mIh5gBhfw2R8ZXBkjZF9Oa Cxz2Jcx4uzehP3Ixzoq9lvIuEK8xuto= X-MC-Unique: X7lw1rwHOBihc1G4Qvmlwg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 6/7] test: Use g_autofree more Date: Mon, 1 Nov 2021 15:16:18 +0100 Message-Id: <2ffae0f31649ee7420b23f3be3c42eed518e5d87.1635776103.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.13 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) X-ZM-MESSAGEID: 1635776220577100001 Content-Type: text/plain; charset="utf-8" This commit doesn't aim to extinguish every VIR_FREE() call, but only those which were touched by the previous commit. The aim is to drop cleanup/error labels. Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- tests/qemuagenttest.c | 3 +-- tests/qemumonitorjsontest.c | 3 +-- tests/qemumonitortestutils.c | 6 ++---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index 402c290056..479f4c0503 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -624,7 +624,7 @@ testQemuAgentCPU(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); - qemuAgentCPUInfo *cpuinfo =3D NULL; + g_autofree qemuAgentCPUInfo *cpuinfo =3D NULL; int nvcpus; int ret =3D -1; =20 @@ -694,7 +694,6 @@ testQemuAgentCPU(const void *data) ret =3D 0; =20 cleanup: - VIR_FREE(cpuinfo); return ret; } =20 diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index e51d6768d5..e4bc656308 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -247,7 +247,7 @@ testQemuMonitorJSONGetVersion(const void *opaque) int major; int minor; int micro; - char *package =3D NULL; + g_autofree char *package =3D NULL; g_autoptr(qemuMonitorTest) test =3D NULL; =20 if (!(test =3D qemuMonitorTestNewSchema(xmlopt, data->schema))) @@ -337,7 +337,6 @@ testQemuMonitorJSONGetVersion(const void *opaque) ret =3D 0; =20 cleanup: - VIR_FREE(package); return ret; } =20 diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 2c63e95bda..2ca17f7f48 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -997,8 +997,8 @@ qemuMonitorCommonTestNew(virDomainXMLOption *xmlopt, virDomainChrSourceDef *src) { g_autoptr(qemuMonitorTest) test =3D NULL; - char *path =3D NULL; - char *tmpdir_template =3D NULL; + g_autofree char *path =3D NULL; + g_autofree char *tmpdir_template =3D NULL; =20 test =3D g_new0(qemuMonitorTest, 1); =20 @@ -1047,8 +1047,6 @@ qemuMonitorCommonTestNew(virDomainXMLOption *xmlopt, return g_steal_pointer(&test); =20 error: - VIR_FREE(path); - VIR_FREE(tmpdir_template); return NULL; =20 } --=20 2.32.0 From nobody Sun May 5 02:25:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1635776220; cv=none; d=zohomail.com; s=zohoarc; b=gde/M7sCtAnksHRmcvyq3D18DArT1r1FiJKfTM8t847jDqx6iqcJ81pwy9ZOkYvARaFdMCfZHNNsrtUr3eqZGjQAuXM+peXWWYyf91pUMjk551oSxt2UZSM55EpzeWxUqcdKO3C3f8JgZWOtYtdGOBdzxmj77hpCG/pRZPi5Qyk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635776220; 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=CAKWW9WugpwCT/EoQmUql1wOtlJEN9dcAiyey8fw0vg=; b=bsQv7kSMJkFG0sR8VTYL9zCtmv20bBVnHhIJDjQv/yujY1ItL4bGAeFDiUM6uNwJvUu2Q5X2rnC/yUPkDPwMN2P7E5313x4tjwgH0zCjLECyjqcgNKyxl1GeG8fyD8tImcZ/878bjKagrPdg7+gyBTfSfjPeTPUwck/VlvNen3U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1635776220665243.31341079233994; Mon, 1 Nov 2021 07:17:00 -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-167-7nb9uHAOMbuqAyL40CezAQ-1; Mon, 01 Nov 2021 10:16:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C87FB18125DF; Mon, 1 Nov 2021 14:16:51 +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 4347E70958; Mon, 1 Nov 2021 14:16:51 +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 02ECB4EA3C; Mon, 1 Nov 2021 14:16:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1A1EGYvk023126 for ; Mon, 1 Nov 2021 10:16:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5277560C0F; Mon, 1 Nov 2021 14:16:34 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id A737160C17 for ; Mon, 1 Nov 2021 14:16:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635776219; 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=CAKWW9WugpwCT/EoQmUql1wOtlJEN9dcAiyey8fw0vg=; b=g4bMxlrlILMb+4gAEPeZRqrs0VEXor00xeNCc6Hv54wZaxGv+ghOd0zm60lFvXUEWlrMIA iOdWQc4EhDQB8bXPCoHeZklmYxN+jTiNN53ZUp2+b8XDCMCPXeEsyBKA1JQ7gmnTZEVYJ8 FWNtrtU73LRm37qn60d3Ip/Vg2xhzco= X-MC-Unique: 7nb9uHAOMbuqAyL40CezAQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 7/7] tests: Drop cleanup/error labels Date: Mon, 1 Nov 2021 15:16:19 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.13 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) X-ZM-MESSAGEID: 1635776222643100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Michal Privoznik Reviewed-by: Tim Wiederhake --- tests/qemuagenttest.c | 216 +++++++++++++++-------------------- tests/qemucapabilitiestest.c | 19 ++- tests/qemumigparamstest.c | 34 +++--- tests/qemumonitorjsontest.c | 67 +++++------ tests/qemumonitortestutils.c | 32 ++---- 5 files changed, 149 insertions(+), 219 deletions(-) diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c index 479f4c0503..6a5aa3edd2 100644 --- a/tests/qemuagenttest.c +++ b/tests/qemuagenttest.c @@ -111,48 +111,45 @@ testQemuAgentFSFreeze(const void *data) virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); const char *mountpoints[] =3D {"/fs1", "/fs2", "/fs3", "/fs4", "/fs5"}; - int ret =3D -1; + int rc; =20 if (!test) return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "guest-fsfreeze-freeze-list", "{ \"return\" : 5 }") < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "guest-fsfreeze-freeze", "{ \"return\" : 7 }") < 0) - goto cleanup; + return -1; =20 - if ((ret =3D qemuAgentFSFreeze(qemuMonitorTestGetAgent(test), - mountpoints, 5)) < 0) - goto cleanup; + if ((rc =3D qemuAgentFSFreeze(qemuMonitorTestGetAgent(test), + mountpoints, 5)) < 0) + return -1; =20 - if (ret !=3D 5) { + if (rc !=3D 5) { virReportError(VIR_ERR_INTERNAL_ERROR, - "expected 5 frozen filesystems, got %d", ret); - goto cleanup; + "expected 5 frozen filesystems, got %d", rc); + return -1; } =20 - if ((ret =3D qemuAgentFSFreeze(qemuMonitorTestGetAgent(test), NULL, 0)= ) < 0) - goto cleanup; + if ((rc =3D qemuAgentFSFreeze(qemuMonitorTestGetAgent(test), NULL, 0))= < 0) + return -1; =20 - if (ret !=3D 7) { + if (rc !=3D 7) { virReportError(VIR_ERR_INTERNAL_ERROR, - "expected 7 frozen filesystems, got %d", ret); - goto cleanup; + "expected 7 frozen filesystems, got %d", rc); + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -161,47 +158,44 @@ testQemuAgentFSThaw(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); - int ret =3D -1; + int rc; =20 if (!test) return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "guest-fsfreeze-thaw", "{ \"return\" : 5 }") < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "guest-fsfreeze-thaw", "{ \"return\" : 7 }") < 0) - goto cleanup; + return -1; =20 - if ((ret =3D qemuAgentFSThaw(qemuMonitorTestGetAgent(test))) < 0) - goto cleanup; + if ((rc =3D qemuAgentFSThaw(qemuMonitorTestGetAgent(test))) < 0) + return -1; =20 - if (ret !=3D 5) { + if (rc !=3D 5) { virReportError(VIR_ERR_INTERNAL_ERROR, - "expected 5 thawed filesystems, got %d", ret); - goto cleanup; + "expected 5 thawed filesystems, got %d", rc); + return -1; } =20 - if ((ret =3D qemuAgentFSThaw(qemuMonitorTestGetAgent(test))) < 0) - goto cleanup; + if ((rc =3D qemuAgentFSThaw(qemuMonitorTestGetAgent(test))) < 0) + return -1; =20 - if (ret !=3D 7) { + if (rc !=3D 7) { virReportError(VIR_ERR_INTERNAL_ERROR, - "expected 7 thawed filesystems, got %d", ret); - goto cleanup; + "expected 7 thawed filesystems, got %d", rc); + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -210,27 +204,23 @@ testQemuAgentFSTrim(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); - int ret =3D -1; =20 if (!test) return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItemParams(test, "guest-fstrim", "{ \"return\" : {} }", "minimum", "1337", NULL) < 0) - goto cleanup; + return -1; =20 if (qemuAgentFSTrim(qemuMonitorTestGetAgent(test), 1337) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -239,7 +229,6 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOption *xmlopt, qemuMonitorTest **test, virDomainDef **def) { - int ret =3D -1; g_autofree char *domain_filename =3D NULL; g_autoptr(qemuMonitorTest) ret_test =3D NULL; g_autoptr(virDomainDef) ret_def =3D NULL; @@ -254,10 +243,10 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOption *xmlo= pt, =20 if (!(ret_def =3D virDomainDefParseFile(domain_filename, xmlopt, NULL, VIR_DOMAIN_DEF_PARSE_INACT= IVE))) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(ret_test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(ret_test, "guest-get-fsinfo", "{\"return\": [" @@ -293,14 +282,11 @@ testQemuAgentGetFSInfoCommon(virDomainXMLOption *xmlo= pt, " {\"name\": \"sdb1\"," " \"mountpoint\": \"/mnt/disk\"," " \"disk\": [], \"type\": \"xfs\"}]}") < = 0) - goto cleanup; + return -1; =20 *test =3D g_steal_pointer(&ret_test); *def =3D g_steal_pointer(&ret_def); - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 static int @@ -408,43 +394,39 @@ testQemuAgentSuspend(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); - int ret =3D -1; size_t i; =20 if (!test) return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "guest-suspend-ram", "{ \"return\" : {} }") < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "guest-suspend-disk", "{ \"return\" : {} }") < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "guest-suspend-hybrid", "{ \"return\" : {} }") < 0) - goto cleanup; + return -1; =20 /* try the commands - fail if ordering changes */ for (i =3D 0; i < VIR_NODE_SUSPEND_TARGET_LAST; i++) { if (qemuAgentSuspend(qemuMonitorTestGetAgent(test), i) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -506,13 +488,12 @@ testQemuAgentShutdown(const void *data) virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); struct qemuAgentShutdownTestData priv; - int ret =3D -1; =20 if (!test) return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 priv.event =3D QEMU_AGENT_EVENT_SHUTDOWN; priv.mode =3D "halt"; @@ -520,14 +501,14 @@ testQemuAgentShutdown(const void *data) if (qemuMonitorTestAddHandler(test, "guest-shutdown", qemuAgentShutdownTestMonitorHandler, &priv, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuAgentShutdown(qemuMonitorTestGetAgent(test), QEMU_AGENT_SHUTDOWN_HALT) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 priv.event =3D QEMU_AGENT_EVENT_SHUTDOWN; priv.mode =3D "powerdown"; @@ -535,14 +516,14 @@ testQemuAgentShutdown(const void *data) if (qemuMonitorTestAddHandler(test, "guest-shutdown", qemuAgentShutdownTestMonitorHandler, &priv, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuAgentShutdown(qemuMonitorTestGetAgent(test), QEMU_AGENT_SHUTDOWN_POWERDOWN) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 priv.event =3D QEMU_AGENT_EVENT_RESET; priv.mode =3D "reboot"; @@ -551,17 +532,17 @@ testQemuAgentShutdown(const void *data) "guest-shutdown", qemuAgentShutdownTestMonitorHandler, &priv, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuAgentShutdown(qemuMonitorTestGetAgent(test), QEMU_AGENT_SHUTDOWN_REBOOT) < 0) - goto cleanup; + return -1; =20 /* check negative response, so that we can verify that the agent breaks * out from sleep */ =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "guest-shutdown", "{\"error\":" @@ -571,19 +552,16 @@ testQemuAgentShutdown(const void *data) " \"data\":{\"name\":\"guest-shutdown\"= }" " }" "}") < 0) - goto cleanup; + return -1; =20 if (qemuAgentShutdown(qemuMonitorTestGetAgent(test), QEMU_AGENT_SHUTDOWN_REBOOT) !=3D -1) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "agent shutdown command should have failed"); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -626,75 +604,71 @@ testQemuAgentCPU(const void *data) g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); g_autofree qemuAgentCPUInfo *cpuinfo =3D NULL; int nvcpus; - int ret =3D -1; =20 if (!test) return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "guest-get-vcpus", testQemuAgentCPUResponse) < 0) - goto cleanup; + return -1; =20 /* get cpus */ if ((nvcpus =3D qemuAgentGetVCPUs(qemuMonitorTestGetAgent(test), &cpuinfo)) < 0) - goto cleanup; + return -1; =20 if (nvcpus !=3D 4) { virReportError(VIR_ERR_INTERNAL_ERROR, "Expected '4' cpus, got '%d'", nvcpus); - goto cleanup; + return -1; } =20 /* try to unplug one */ if (qemuAgentUpdateCPUInfo(2, cpuinfo, nvcpus) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItemParams(test, "guest-set-vcpus", "{ \"return\" : 1 }", "vcpus", testQemuAgentCPUArguments1, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuAgentSetVCPUs(qemuMonitorTestGetAgent(test), cpuinfo, nvcpus) = < 0) - goto cleanup; + return -1; =20 /* try to hotplug two, second one will fail */ if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItemParams(test, "guest-set-vcpus", "{ \"return\" : 1 }", "vcpus", testQemuAgentCPUArguments2, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItemParams(test, "guest-set-vcpus", "{ \"error\" : \"random error\" }", "vcpus", testQemuAgentCPUArguments3, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuAgentUpdateCPUInfo(4, cpuinfo, nvcpus) < 0) - goto cleanup; + return -1; =20 /* this should fail */ if (qemuAgentSetVCPUs(qemuMonitorTestGetAgent(test), cpuinfo, nvcpus) = !=3D -1) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -706,37 +680,33 @@ testQemuAgentArbitraryCommand(const void *data) { virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); - int ret =3D -1; g_autofree char *reply =3D NULL; =20 if (!test) return -1; =20 if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "ble", testQemuAgentArbitraryCommandResponse) < 0) - goto cleanup; + return -1; =20 if (qemuAgentArbitraryCommand(qemuMonitorTestGetAgent(test), "{\"execute\":\"ble\"}", &reply, VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0) - goto cleanup; + return -1; =20 if (STRNEQ(reply, testQemuAgentArbitraryCommandResponse)) { virReportError(VIR_ERR_INTERNAL_ERROR, "invalid processing of guest agent reply: " "got '%s' expected '%s'", reply, testQemuAgentArbitraryCommandResponse); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -755,36 +725,33 @@ testQemuAgentTimeout(const void *data) virDomainXMLOption *xmlopt =3D (virDomainXMLOption *)data; g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewAgent(xmlopt); g_autofree char *reply =3D NULL; - int ret =3D -1; =20 if (!test) return -1; =20 - if (virTestGetExpensive() =3D=3D 0) { - ret =3D EXIT_AM_SKIP; - goto cleanup; - } + if (virTestGetExpensive() =3D=3D 0) + return EXIT_AM_SKIP; =20 if (qemuMonitorTestAddHandler(test, NULL, qemuAgentTimeoutTestMonitorHandler, NULL, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuAgentFSFreeze(qemuMonitorTestGetAgent(test), NULL, 0) !=3D -1)= { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "agent command should have failed"); - goto cleanup; + return -1; } =20 /* test timeout */ if (qemuMonitorTestAddAgentSyncResponse(test) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddHandler(test, NULL, qemuAgentTimeoutTestMonitorHandler, NULL, NULL) < 0) - goto cleanup; + return -1; =20 if (qemuAgentArbitraryCommand(qemuMonitorTestGetAgent(test), "{\"execute\":\"ble\"}", @@ -792,13 +759,10 @@ testQemuAgentTimeout(const void *data) 1) !=3D -2) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "agent command didn't time out"); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 static const char testQemuAgentGetInterfacesResponse[] =3D diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index b866818e0a..99534ab9a1 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -68,7 +68,6 @@ testQemuDataReset(testQemuData *data) static int testQemuCaps(const void *opaque) { - int ret =3D -1; testQemuData *data =3D (void *) opaque; g_autofree char *repliesFile =3D NULL; g_autofree char *capsFile =3D NULL; @@ -88,10 +87,10 @@ testQemuCaps(const void *opaque) =20 if (!(mon =3D qemuMonitorTestNewFromFileFull(repliesFile, &data->drive= r, NULL, NULL))) - goto cleanup; + return -1; =20 if (qemuProcessQMPInitMonitor(qemuMonitorTestGetMonitor(mon)) < 0) - goto cleanup; + return -1; =20 binary =3D g_strdup_printf("/usr/bin/qemu-system-%s", data->archName); @@ -99,17 +98,17 @@ testQemuCaps(const void *opaque) if (!(capsActual =3D virQEMUCapsNewBinary(binary)) || virQEMUCapsInitQMPMonitor(capsActual, qemuMonitorTestGetMonitor(mon)) < 0) - goto cleanup; + return -1; =20 if (virQEMUCapsGet(capsActual, QEMU_CAPS_KVM)) { qemuMonitorResetCommandID(qemuMonitorTestGetMonitor(mon)); =20 if (qemuProcessQMPInitMonitor(qemuMonitorTestGetMonitor(mon)) < 0) - goto cleanup; + return -1; =20 if (virQEMUCapsInitQMPMonitorTCG(capsActual, qemuMonitorTestGetMonitor(mon)) <= 0) - goto cleanup; + return -1; =20 /* calculate fake microcode version based on filename for a reprod= ucible * number for testing which does not change with the contents */ @@ -125,14 +124,12 @@ testQemuCaps(const void *opaque) } =20 if (!(actual =3D virQEMUCapsFormatCache(capsActual))) - goto cleanup; + return -1; =20 if (virTestCompareToFile(actual, capsFile) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - cleanup: - return ret; + return 0; } =20 =20 diff --git a/tests/qemumigparamstest.c b/tests/qemumigparamstest.c index 7d677e2b3a..ae59ff6757 100644 --- a/tests/qemumigparamstest.c +++ b/tests/qemumigparamstest.c @@ -100,7 +100,6 @@ qemuMigParamsTestXML(const void *opaque) g_autoptr(virJSONValue) params =3D NULL; g_autoptr(qemuMigrationParams) migParams =3D NULL; g_autofree char *actualXML =3D NULL; - int ret =3D -1; =20 replyFile =3D g_strdup_printf("%s/qemumigparamsdata/%s.reply", abs_srcdir, data->name); @@ -108,27 +107,24 @@ qemuMigParamsTestXML(const void *opaque) abs_srcdir, data->name); =20 if (!(mon =3D qemuMonitorTestNewFromFile(replyFile, data->xmlopt, true= ))) - goto cleanup; + return -1; =20 if (qemuMonitorGetMigrationParams(qemuMonitorTestGetMonitor(mon), ¶ms) < 0) - goto cleanup; + return -1; =20 if (!(migParams =3D qemuMigrationParamsFromJSON(params))) - goto cleanup; + return -1; =20 qemuMigParamsTestFormatXML(&buf, migParams); =20 if (!(actualXML =3D virBufferContentAndReset(&buf))) - goto cleanup; + return -1; =20 if (virTestCompareToFile(actualXML, xmlFile) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -144,7 +140,6 @@ qemuMigParamsTestJSON(const void *opaque) g_autoptr(qemuMigrationParams) migParams =3D NULL; g_autofree char *actualJSON =3D NULL; g_auto(virBuffer) debug =3D VIR_BUFFER_INITIALIZER; - int ret =3D -1; =20 replyFile =3D g_strdup_printf("%s/qemumigparamsdata/%s.reply", abs_srcdir, data->name); @@ -152,18 +147,18 @@ qemuMigParamsTestJSON(const void *opaque) abs_srcdir, data->name); =20 if (!(mon =3D qemuMonitorTestNewFromFile(replyFile, data->xmlopt, true= ))) - goto cleanup; + return -1; =20 if (qemuMonitorGetMigrationParams(qemuMonitorTestGetMonitor(mon), ¶msIn) < 0) - goto cleanup; + return -1; =20 if (!(migParams =3D qemuMigrationParamsFromJSON(paramsIn))) - goto cleanup; + return -1; =20 if (!(paramsOut =3D qemuMigrationParamsToJSON(migParams)) || !(actualJSON =3D virJSONValueToString(paramsOut, true))) - goto cleanup; + return -1; =20 if (testQEMUSchemaValidateCommand("migrate-set-parameters", paramsOut, @@ -174,16 +169,13 @@ qemuMigParamsTestJSON(const void *opaque) &debug) < 0) { VIR_TEST_VERBOSE("failed to validate migration params '%s' against= QMP schema: %s", actualJSON, virBufferCurrentContent(&debug)); - goto cleanup; + return -1; } =20 if (virTestCompareToFile(actualJSON, jsonFile) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index e4bc656308..8e552a4b20 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -243,7 +243,6 @@ testQemuMonitorJSONGetVersion(const void *opaque) { const testGenericData *data =3D opaque; virDomainXMLOption *xmlopt =3D data->xmlopt; - int ret =3D -1; int major; int minor; int micro; @@ -264,7 +263,7 @@ testQemuMonitorJSONGetVersion(const void *opaque) " \"package\":\"\"" " }" "}") < 0) - goto cleanup; + return -1; =20 if (qemuMonitorTestAddItem(test, "query-version", "{ " @@ -277,67 +276,64 @@ testQemuMonitorJSONGetVersion(const void *opaque) " \"package\":\"2.283.el6\"" " }" "}") < 0) - goto cleanup; + return -1; =20 if (qemuMonitorGetVersion(qemuMonitorTestGetMonitor(test), &major, &minor, µ, &package) < 0) - goto cleanup; + return -1; =20 if (major !=3D 1) { virReportError(VIR_ERR_INTERNAL_ERROR, "Major %d was not 1", major); - goto cleanup; + return -1; } if (minor !=3D 2) { virReportError(VIR_ERR_INTERNAL_ERROR, "Minor %d was not 2", major); - goto cleanup; + return -1; } if (micro !=3D 3) { virReportError(VIR_ERR_INTERNAL_ERROR, "Micro %d was not 3", major); - goto cleanup; + return -1; } =20 if (STRNEQ(package, "")) { virReportError(VIR_ERR_INTERNAL_ERROR, "Package %s was not ''", package); - goto cleanup; + return -1; } VIR_FREE(package); =20 if (qemuMonitorGetVersion(qemuMonitorTestGetMonitor(test), &major, &minor, µ, &package) < 0) - goto cleanup; + return -1; =20 if (major !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "Major %d was not 0", major); - goto cleanup; + return -1; } if (minor !=3D 11) { virReportError(VIR_ERR_INTERNAL_ERROR, "Minor %d was not 11", major); - goto cleanup; + return -1; } if (micro !=3D 6) { virReportError(VIR_ERR_INTERNAL_ERROR, "Micro %d was not 6", major); - goto cleanup; + return -1; } =20 if (STRNEQ(package, "2.283.el6")) { virReportError(VIR_ERR_INTERNAL_ERROR, "Package %s was not '2.283.el6'", package); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 static int @@ -652,10 +648,9 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOption= *xmlopt, g_autoptr(qemuMonitorTest) test =3D qemuMonitorTestNewSchema(xmlopt, s= chema); g_autofree char *jsonreply =3D NULL; g_autofree char *fulllabel =3D NULL; - int ret =3D -1; =20 if (!test) - goto cleanup; + return -1; =20 if (!reply) reply =3D ""; @@ -668,7 +663,7 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOption = *xmlopt, =20 if (qemuMonitorTestAddItemExpect(test, "chardev-add", expectargs, true, jsonreply) < 0) - goto cleanup; + return -1; =20 data.chr =3D chr; data.fail =3D fail; @@ -676,12 +671,9 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOption= *xmlopt, data.test =3D test; =20 if (virTestRun(fulllabel, &testQemuMonitorJSONAttachChardev, &data) < = 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 static int @@ -1028,15 +1020,15 @@ testQemuMonitorJSONGetDeviceAliases(const void *opa= que) " \"type\": \"child\"}," " {\"name\": \"type\", \"type\": \"string\"= }" "]}") < 0) - goto cleanup; + return -1; =20 if (qemuMonitorJSONGetDeviceAliases(qemuMonitorTestGetMonitor(test), &aliases) < 0) - goto cleanup; + return -1; =20 if (!aliases) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "no aliases returned"= ); - goto cleanup; + return -1; } =20 ret =3D 0; @@ -1053,7 +1045,6 @@ testQemuMonitorJSONGetDeviceAliases(const void *opaqu= e) } } =20 - cleanup: return ret; } =20 @@ -2840,7 +2831,6 @@ testQemuMonitorJSONqemuMonitorJSONGetCPUModelBaseline= (const void *opaque) g_autoptr(virCPUDef) cpu_a =3D virCPUDefNew(); g_autoptr(virCPUDef) cpu_b =3D virCPUDefNew(); g_autoptr(qemuMonitorCPUModelInfo) baseline =3D NULL; - int ret =3D -1; =20 if (!(test =3D qemuMonitorTestNewSchema(data->xmlopt, data->schema))) return -1; @@ -2865,26 +2855,26 @@ testQemuMonitorJSONqemuMonitorJSONGetCPUModelBaseli= ne(const void *opaque) if (virCPUDefAddFeature(cpu_a, "feat_a", VIR_CPU_FEATURE_REQUIRE) < 0 = || virCPUDefAddFeature(cpu_a, "feat_b", VIR_CPU_FEATURE_REQUIRE) < 0 = || virCPUDefAddFeature(cpu_a, "feat_c", VIR_CPU_FEATURE_REQUIRE) < 0) - goto cleanup; + return -1; =20 if (qemuMonitorJSONGetCPUModelBaseline(qemuMonitorTestGetMonitor(test), cpu_a, cpu_b, &baseline) < 0) - goto cleanup; + return -1; =20 if (!baseline) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Baseline missing result"); - goto cleanup; + return -1; } if (!baseline->name) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Baseline missing model name"); - goto cleanup; + return -1; } if (baseline->nprops !=3D 2) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Baseline missing properties"); - goto cleanup; + return -1; } if (STRNEQ(baseline->props[0].name, "feat_a") || !baseline->props[0].value.boolean || @@ -2892,13 +2882,10 @@ testQemuMonitorJSONqemuMonitorJSONGetCPUModelBaseli= ne(const void *opaque) baseline->props[1].value.boolean) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Baseline property error"); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 2ca17f7f48..0d99b45909 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -1014,7 +1014,7 @@ qemuMonitorCommonTestNew(virDomainXMLOption *xmlopt, if (!(test->tmpdir =3D g_mkdtemp(tmpdir_template))) { virReportSystemError(errno, "%s", "Failed to create temporary directory"); - goto error; + return NULL; } =20 tmpdir_template =3D NULL; @@ -1026,14 +1026,14 @@ qemuMonitorCommonTestNew(virDomainXMLOption *xmlopt, } else { test->vm =3D virDomainObjNew(xmlopt); if (!test->vm) - goto error; + return NULL; if (!(test->vm->def =3D virDomainDefNew(xmlopt))) - goto error; + return NULL; } =20 if (virNetSocketNewListenUNIX(path, 0700, geteuid(), getegid(), &test->server) < 0) - goto error; + return NULL; =20 memset(src, 0, sizeof(*src)); src->type =3D VIR_DOMAIN_CHR_TYPE_UNIX; @@ -1042,13 +1042,9 @@ qemuMonitorCommonTestNew(virDomainXMLOption *xmlopt, path =3D NULL; =20 if (virNetSocketListen(test->server, 1) < 0) - goto error; + return NULL; =20 return g_steal_pointer(&test); - - error: - return NULL; - } =20 =20 @@ -1200,12 +1196,12 @@ qemuMonitorTestNewFromFile(const char *fileName, =20 if (test) { if (qemuMonitorTestAddItem(test, NULL, singleReply) < 0) - goto error; + return NULL; } else { /* Create new mocked monitor with our greeting */ if (!(test =3D qemuMonitorTestNew(xmlopt, NULL, NULL, singleReply, NULL))) - goto error; + return NULL; } =20 if (!eof) { @@ -1220,12 +1216,9 @@ qemuMonitorTestNewFromFile(const char *fileName, } =20 if (test && qemuMonitorTestAddItem(test, NULL, singleReply) < 0) - goto error; + return NULL; =20 return g_steal_pointer(&test); - - error: - return NULL; } =20 =20 @@ -1344,7 +1337,7 @@ qemuMonitorTestNewFromFileFull(const char *fileName, if (response) { if (qemuMonitorTestFullAddItem(ret, fileName, command, response, commandln) < 0) - goto error; + return NULL; command =3D NULL; response =3D NULL; } @@ -1364,18 +1357,15 @@ qemuMonitorTestNewFromFileFull(const char *fileName, if (!response) { virReportError(VIR_ERR_INTERNAL_ERROR, "missing response for c= ommand " "on line '%zu' in '%s'", commandln, fileName); - goto error; + return NULL; } =20 if (qemuMonitorTestFullAddItem(ret, fileName, command, response, commandln) < 0) - goto error; + return NULL; } =20 return g_steal_pointer(&ret); - - error: - return NULL; } =20 =20 --=20 2.32.0