From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174862888580.1656700815203; Sat, 21 Jul 2018 05:07:42 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id C6E2181F0E; Sat, 21 Jul 2018 12:07:39 +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 5B9DB5C20D; Sat, 21 Jul 2018 12:07:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 330D24EE0C; Sat, 21 Jul 2018 12:07:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC7bkl016182 for ; Sat, 21 Jul 2018 08:07:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 860B95B681; Sat, 21 Jul 2018 12:07:37 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C41D5B680 for ; Sat, 21 Jul 2018 12:07:37 +0000 (UTC) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92F24C04B940 for ; Sat, 21 Jul 2018 12:07:25 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id r5-v6so8969332pgv.0 for ; Sat, 21 Jul 2018 05:07:25 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=u3MxVR4Z4yxI9TJZi3xiZC2iaTY44eWrcPyczylLcaY=; b=YcO6Y0f3xqF8yeERCyq4Yayvk6ltEQOxsVbsxoEsExRhU3n8De28tadUVVO8jhN0xi pCW2P1gpcEQ/lxu5RYnC+LPDCo/A47tbh+I90N0laPtVlP85OtaasFzubsgydJVdYo1V /Ak4n1PXLyD6HN23mC4W4wE//5o3ouR6ilKGCd87kF32IaQmy0xt0uNRDY06Wn60DQnA E0BlLYBEB+yGWlUB/Ld7VvwALtRtvaZnxghGukC5eRNKdYq93PW3P6uh8MVOASlWTSY8 ADIruKRjBm4nSBVt6DhwA/Jv3/J3a2VAgkUkVQLCOIrhkZj/1FHS1QfzRYg+AT/+EhmZ K8Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=u3MxVR4Z4yxI9TJZi3xiZC2iaTY44eWrcPyczylLcaY=; b=STDcpLoGbpYQ/OAFpODAXXuE4M3DJyOrr0CaUBBQxVuMDY2Cyb/6ejZhpR2vTNaJTh Xx6U2/mo2v357jRU/lVZA1UdexufgQads2kRNYZ9WB24NL79njBJDHG4HeJs2Ch9Wqio d3m3h/qpkDHBV18Z2tpoScZkGgKcEbOXSS2Bav6EsS3cT71HLtMqtgvimf6cIaTdd2qf XIBn04yg0Qk1JIr8MzghUSp3hqYwLPnYZDT9KP+z/MG2LciWnLQUEFE1MJAx7rDRG+vr P4+lLcLiJIoTM4YJCXWgwryXmAP5M45GPGog93wDqQRampx8a+XquGhzDa6IV78Ug/Xk L54g== X-Gm-Message-State: AOUpUlGJ/nCv/N082eIifGSTgMQ21yZC6cZNeJCEWwiU5feDI0zkcZCf nr6/RUMmGRRcE/zsq3cadbfGdXzG X-Google-Smtp-Source: AAOMgpfMqLKoZV0DgyELOPBA/u2A3t5EZdQxc7rlH5/l/0kQdj6yAWgZq0WPxYrat93aNloklqqbSA== X-Received: by 2002:a63:7252:: with SMTP id c18-v6mr5331834pgn.186.1532174844703; Sat, 21 Jul 2018 05:07:24 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:33 +0530 Message-Id: <1532174832-21644-2-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 21 Jul 2018 12:07:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 21 Jul 2018 12:07:25 +0000 (UTC) for IP:'209.85.215.174' DOMAIN:'mail-pg1-f174.google.com' HELO:'mail-pg1-f174.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.174 mail-pg1-f174.google.com 209.85.215.174 mail-pg1-f174.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 01/40] util: cgroup: modify virCgroupFree to take virCgroupPtr 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 21 Jul 2018 12:07:42 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modify virCgroupFree function signature to take a value of type virCgroupPtr instead of virCgroupPtr * as the parameter. Change the argument type in all calls to virCgroupFree function from virCgroupPtr * to virCgroupPtr. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/libvirt-lxc.c | 4 ++-- src/lxc/lxc_cgroup.c | 4 ++-- src/lxc/lxc_container.c | 2 +- src/lxc/lxc_controller.c | 2 +- src/lxc/lxc_domain.c | 2 +- src/lxc/lxc_process.c | 10 ++++----- src/qemu/qemu_cgroup.c | 16 +++++++------- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_driver.c | 34 ++++++++++++++--------------- src/qemu/qemu_process.c | 2 +- src/util/vircgroup.c | 56 ++++++++++++++++++++++++--------------------= ---- src/util/vircgroup.h | 2 +- tests/vircgrouptest.c | 42 ++++++++++++++++++------------------ 13 files changed, 88 insertions(+), 90 deletions(-) diff --git a/src/libvirt-lxc.c b/src/libvirt-lxc.c index c9f2146..12be893 100644 --- a/src/libvirt-lxc.c +++ b/src/libvirt-lxc.c @@ -309,12 +309,12 @@ int virDomainLxcEnterCGroup(virDomainPtr domain, if (virCgroupAddTask(cgroup, getpid()) < 0) goto error; =20 - virCgroupFree(&cgroup); + virCgroupFree(cgroup); =20 return 0; =20 error: virDispatchError(NULL); - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return -1; } diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c index 8e937ec..873c843 100644 --- a/src/lxc/lxc_cgroup.c +++ b/src/lxc/lxc_cgroup.c @@ -306,7 +306,7 @@ int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo) =20 ret =3D 0; cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -515,7 +515,7 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def, def->idmap.uidmap[0].target, def->idmap.gidmap[0].target, (1 << VIR_CGROUP_CONTROLLER_SYSTEMD)) < 0) { - virCgroupFree(&cgroup); + virCgroupFree(cgroup); cgroup =3D NULL; goto cleanup; } diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 3a1b2d6..407214f 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -1815,7 +1815,7 @@ static int lxcContainerSetupPivotRoot(virDomainDefPtr= vmDef, =20 cleanup: VIR_FREE(stateDir); - virCgroupFree(&cgroup); + virCgroupFree(cgroup); VIR_FREE(sec_mount_options); return ret; } diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 4e84391..7be45f8 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -296,7 +296,7 @@ static void virLXCControllerFree(virLXCControllerPtr ct= rl) VIR_FREE(ctrl->nbdpids); =20 VIR_FREE(ctrl->nsFDs); - virCgroupFree(&ctrl->cgroup); + virCgroupFree(ctrl->cgroup); =20 /* This must always be the last thing to be closed */ VIR_FORCE_CLOSE(ctrl->handshakeFd); diff --git a/src/lxc/lxc_domain.c b/src/lxc/lxc_domain.c index b197f9d..eb0071d 100644 --- a/src/lxc/lxc_domain.c +++ b/src/lxc/lxc_domain.c @@ -172,7 +172,7 @@ virLXCDomainObjPrivateFree(void *data) { virLXCDomainObjPrivatePtr priv =3D data; =20 - virCgroupFree(&priv->cgroup); + virCgroupFree(priv->cgroup); virLXCDomainObjFreeJob(priv); VIR_FREE(priv); } diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 14502e1..8534051 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -220,7 +220,7 @@ static void virLXCProcessCleanup(virLXCDriverPtr driver, =20 if (priv->cgroup) { virCgroupRemove(priv->cgroup); - virCgroupFree(&priv->cgroup); + virCgroupFree(priv->cgroup); } =20 /* Get machined to terminate the machine as it may not have cleaned it @@ -1203,26 +1203,26 @@ int virLXCProcessStart(virConnectPtr conn, =20 if (!virCgroupHasController(selfcgroup, VIR_CGROUP_CONTROLLER_CPUACCT)) { - virCgroupFree(&selfcgroup); + virCgroupFree(selfcgroup); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to find 'cpuacct' cgroups controller moun= t")); return -1; } if (!virCgroupHasController(selfcgroup, VIR_CGROUP_CONTROLLER_DEVICES)) { - virCgroupFree(&selfcgroup); + virCgroupFree(selfcgroup); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to find 'devices' cgroups controller moun= t")); return -1; } if (!virCgroupHasController(selfcgroup, VIR_CGROUP_CONTROLLER_MEMORY)) { - virCgroupFree(&selfcgroup); + virCgroupFree(selfcgroup); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to find 'memory' cgroups controller mount= ")); return -1; } - virCgroupFree(&selfcgroup); + virCgroupFree(selfcgroup); =20 if (vm->def->nconsoles =3D=3D 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 43e17d7..8a00ffc 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -841,7 +841,7 @@ qemuSetupCpusetMems(virDomainObjPtr vm) ret =3D 0; cleanup: VIR_FREE(mem_mask); - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); return ret; } =20 @@ -920,7 +920,7 @@ qemuInitCgroup(virDomainObjPtr vm, if (!virCgroupAvailable()) goto done; =20 - virCgroupFree(&priv->cgroup); + virCgroupFree(priv->cgroup); =20 if (!vm->def->resource) { virDomainResourceDefPtr res; @@ -1008,7 +1008,7 @@ qemuRestoreCgroupState(virDomainObjPtr vm) goto cleanup; =20 VIR_FREE(nodeset); - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); } =20 for (i =3D 0; i < vm->def->niothreadids; i++) { @@ -1021,7 +1021,7 @@ qemuRestoreCgroupState(virDomainObjPtr vm) goto cleanup; =20 VIR_FREE(nodeset); - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); } =20 if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0, @@ -1035,7 +1035,7 @@ qemuRestoreCgroupState(virDomainObjPtr vm) VIR_FREE(mem_mask); VIR_FREE(nodeset); virBitmapFree(all_nodes); - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); return; =20 error: @@ -1057,7 +1057,7 @@ qemuConnectCgroup(virDomainObjPtr vm) if (!virCgroupAvailable()) goto done; =20 - virCgroupFree(&priv->cgroup); + virCgroupFree(priv->cgroup); =20 if (virCgroupNewDetectMachine(vm->def->name, "qemu", @@ -1203,7 +1203,7 @@ qemuSetupCgroupForExtDevices(virDomainObjPtr vm, ret =3D qemuExtDevicesSetupCgroup(driver, vm->def, cgroup_temp); =20 cleanup: - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); =20 return ret; } @@ -1281,7 +1281,7 @@ qemuCgroupEmulatorAllNodesDataFree(qemuCgroupEmulator= AllNodesDataPtr data) if (!data) return; =20 - virCgroupFree(&data->emulatorCgroup); + virCgroupFree(data->emulatorCgroup); VIR_FREE(data->emulatorMemMask); VIR_FREE(data); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9188302..26eeb8f 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1920,7 +1920,7 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivatePtr= priv) virStringListFree(priv->qemuDevices); priv->qemuDevices =3D NULL; =20 - virCgroupFree(&priv->cgroup); + virCgroupFree(priv->cgroup); =20 virPerfFree(priv->perf); priv->perf =3D NULL; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8cdb04e..606fd72 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5075,7 +5075,7 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm, =20 cleanup: virBitmapFree(tmpmap); - virCgroupFree(&cgroup_vcpu); + virCgroupFree(cgroup_vcpu); VIR_FREE(str); virObjectEventStateQueue(driver->domainEventState, event); return ret; @@ -5312,8 +5312,7 @@ qemuDomainPinEmulator(virDomainPtr dom, qemuDomainObjEndJob(driver, vm); =20 cleanup: - if (cgroup_emulator) - virCgroupFree(&cgroup_emulator); + virCgroupFree(cgroup_emulator); virObjectEventStateQueue(driver->domainEventState, event); VIR_FREE(str); virBitmapFree(pcpumap); @@ -5794,8 +5793,7 @@ qemuDomainPinIOThread(virDomainPtr dom, qemuDomainObjEndJob(driver, vm); =20 cleanup: - if (cgroup_iothread) - virCgroupFree(&cgroup_iothread); + virCgroupFree(cgroup_iothread); virObjectEventStateQueue(driver->domainEventState, event); VIR_FREE(str); virBitmapFree(pcpumap); @@ -9855,7 +9853,7 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm, false, &cgroup_temp) < 0 || virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) goto cleanup; - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); =20 for (i =3D 0; i < virDomainDefGetVcpusMax(vm->def); i++) { virDomainVcpuDefPtr vcpu =3D virDomainDefGetVcpu(vm->def, i); @@ -9867,7 +9865,7 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm, false, &cgroup_temp) < 0 || virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) goto cleanup; - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); } =20 for (i =3D 0; i < vm->def->niothreadids; i++) { @@ -9876,13 +9874,13 @@ qemuDomainSetNumaParamsLive(virDomainObjPtr vm, false, &cgroup_temp) < 0 || virCgroupSetCpusetMems(cgroup_temp, nodeset_str) < 0) goto cleanup; - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); } =20 ret =3D 0; cleanup: VIR_FREE(nodeset_str); - virCgroupFree(&cgroup_temp); + virCgroupFree(cgroup_temp); =20 return ret; } @@ -10304,13 +10302,13 @@ qemuSetVcpusBWLive(virDomainObjPtr vm, virCgroupP= tr cgroup, if (qemuSetupCgroupVcpuBW(cgroup_vcpu, period, quota) < 0) goto cleanup; =20 - virCgroupFree(&cgroup_vcpu); + virCgroupFree(cgroup_vcpu); } =20 return 0; =20 cleanup: - virCgroupFree(&cgroup_vcpu); + virCgroupFree(cgroup_vcpu); return -1; } =20 @@ -10331,11 +10329,11 @@ qemuSetEmulatorBandwidthLive(virCgroupPtr cgroup, if (qemuSetupCgroupVcpuBW(cgroup_emulator, period, quota) < 0) goto cleanup; =20 - virCgroupFree(&cgroup_emulator); + virCgroupFree(cgroup_emulator); return 0; =20 cleanup: - virCgroupFree(&cgroup_emulator); + virCgroupFree(cgroup_emulator); return -1; } =20 @@ -10362,13 +10360,13 @@ qemuSetIOThreadsBWLive(virDomainObjPtr vm, virCgr= oupPtr cgroup, if (qemuSetupCgroupVcpuBW(cgroup_iothread, period, quota) < 0) goto cleanup; =20 - virCgroupFree(&cgroup_iothread); + virCgroupFree(cgroup_iothread); } =20 return 0; =20 cleanup: - virCgroupFree(&cgroup_iothread); + virCgroupFree(cgroup_iothread); return -1; } =20 @@ -10754,7 +10752,7 @@ qemuGetVcpusBWLive(virDomainObjPtr vm, ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup_vcpu); + virCgroupFree(cgroup_vcpu); return ret; } =20 @@ -10777,7 +10775,7 @@ qemuGetEmulatorBandwidthLive(virCgroupPtr cgroup, ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup_emulator); + virCgroupFree(cgroup_emulator); return ret; } =20 @@ -10813,7 +10811,7 @@ qemuGetIOThreadsBWLive(virDomainObjPtr vm, ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup_iothread); + virCgroupFree(cgroup_iothread); return ret; } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a4b1f97..b3abaae 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -2532,7 +2532,7 @@ qemuProcessSetupPid(virDomainObjPtr vm, if (cgroup) { if (ret < 0) virCgroupRemove(cgroup); - virCgroupFree(&cgroup); + virCgroupFree(cgroup); } =20 return ret; diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index e810a3d..140b016 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -1178,7 +1178,7 @@ virCgroupNew(pid_t pid, return 0; =20 error: - virCgroupFree(group); + virCgroupFree(*group); *group =3D NULL; =20 return -1; @@ -1379,8 +1379,8 @@ virCgroupNewPartition(const char *path, ret =3D 0; cleanup: if (ret !=3D 0) - virCgroupFree(group); - virCgroupFree(&parent); + virCgroupFree(*group); + virCgroupFree(parent); VIR_FREE(parentPath); VIR_FREE(newPath); return ret; @@ -1447,7 +1447,7 @@ virCgroupNewDomainPartition(virCgroupPtr partition, if (virCgroupMakeGroup(partition, *group, create, VIR_CGROUP_MEM_HIERACHY) < 0) { virCgroupRemove(*group); - virCgroupFree(group); + virCgroupFree(*group); goto cleanup; } =20 @@ -1509,7 +1509,7 @@ virCgroupNewThread(virCgroupPtr domain, =20 if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE) < 0) { virCgroupRemove(*group); - virCgroupFree(group); + virCgroupFree(*group); goto cleanup; } =20 @@ -1550,7 +1550,7 @@ virCgroupNewDetectMachine(const char *name, true, machinename)) { VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'", name, drivername); - virCgroupFree(group); + virCgroupFree(*group); return 0; } =20 @@ -1603,7 +1603,7 @@ virCgroupNewMachineSystemd(const char *name, =20 path =3D init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement; init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement =3D NULL; - virCgroupFree(&init); + virCgroupFree(init); =20 if (!path || STREQ(path, "/") || path[0] !=3D '/') { VIR_DEBUG("Systemd didn't setup its controller"); @@ -1635,13 +1635,13 @@ virCgroupNewMachineSystemd(const char *name, goto cleanup; =20 if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_NONE) < 0) { - virCgroupFree(&tmp); + virCgroupFree(tmp); goto cleanup; } if (t) { *t =3D '/'; offset =3D t; - virCgroupFree(&parent); + virCgroupFree(parent); parent =3D tmp; } else { *group =3D tmp; @@ -1652,7 +1652,7 @@ virCgroupNewMachineSystemd(const char *name, if (virCgroupAddTask(*group, pidleader) < 0) { virErrorPtr saved =3D virSaveLastError(); virCgroupRemove(*group); - virCgroupFree(group); + virCgroupFree(*group); if (saved) { virSetError(saved); virFreeError(saved); @@ -1661,7 +1661,7 @@ virCgroupNewMachineSystemd(const char *name, =20 ret =3D 0; cleanup: - virCgroupFree(&parent); + virCgroupFree(parent); VIR_FREE(path); return ret; } @@ -1708,7 +1708,7 @@ virCgroupNewMachineManual(const char *name, if (virCgroupAddTask(*group, pidleader) < 0) { virErrorPtr saved =3D virSaveLastError(); virCgroupRemove(*group); - virCgroupFree(group); + virCgroupFree(*group); if (saved) { virSetError(saved); virFreeError(saved); @@ -1719,7 +1719,7 @@ virCgroupNewMachineManual(const char *name, ret =3D 0; =20 cleanup: - virCgroupFree(&parent); + virCgroupFree(parent); return ret; } =20 @@ -1786,21 +1786,21 @@ virCgroupNewIgnoreError(void) * @group: The group structure to free */ void -virCgroupFree(virCgroupPtr *group) +virCgroupFree(virCgroupPtr group) { size_t i; =20 - if (*group =3D=3D NULL) + if (!group) return; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - VIR_FREE((*group)->controllers[i].mountPoint); - VIR_FREE((*group)->controllers[i].linkPoint); - VIR_FREE((*group)->controllers[i].placement); + VIR_FREE(group->controllers[i].mountPoint); + VIR_FREE(group->controllers[i].linkPoint); + VIR_FREE(group->controllers[i].placement); } =20 - VIR_FREE((*group)->path); - VIR_FREE(*group); + VIR_FREE(group->path); + VIR_FREE(group); } =20 =20 @@ -2514,7 +2514,7 @@ virCgroupMemoryOnceInit(void) "memory.limit_in_bytes", &mem_unlimited)); cleanup: - virCgroupFree(&group); + virCgroupFree(group); virCgroupMemoryUnlimitedKB =3D mem_unlimited >> 10; } =20 @@ -3158,13 +3158,13 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group, sum_cpu_time[j] +=3D tmp; } =20 - virCgroupFree(&group_vcpu); + virCgroupFree(group_vcpu); VIR_FREE(buf); } =20 ret =3D 0; cleanup: - virCgroupFree(&group_vcpu); + virCgroupFree(group_vcpu); VIR_FREE(buf); return ret; } @@ -3722,7 +3722,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, if (dormdir) virCgroupRemove(subgroup); =20 - virCgroupFree(&subgroup); + virCgroupFree(subgroup); } if (direrr < 0) goto cleanup; @@ -3731,7 +3731,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, ret =3D killedAny ? 1 : 0; =20 cleanup: - virCgroupFree(&subgroup); + virCgroupFree(subgroup); VIR_FREE(keypath); VIR_DIR_CLOSE(dp); return ret; @@ -4118,7 +4118,7 @@ virCgroupControllerAvailable(int controller) return ret; =20 ret =3D virCgroupHasController(cgroup, controller); - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -4250,7 +4250,7 @@ virCgroupNewIgnoreError(void) =20 =20 void -virCgroupFree(virCgroupPtr *group ATTRIBUTE_UNUSED) +virCgroupFree(virCgroupPtr group ATTRIBUTE_UNUSED) { virReportSystemError(ENXIO, "%s", _("Control groups not supported on this platform"= )); @@ -4915,7 +4915,7 @@ virCgroupDelThread(virCgroupPtr cgroup, =20 /* Remove the offlined cgroup */ virCgroupRemove(new_cgroup); - virCgroupFree(&new_cgroup); + virCgroupFree(new_cgroup); } =20 return 0; diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index d833927..e4ffd57 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -122,7 +122,7 @@ int virCgroupTerminateMachine(const char *name) =20 bool virCgroupNewIgnoreError(void); =20 -void virCgroupFree(virCgroupPtr *group); +void virCgroupFree(virCgroupPtr group); =20 bool virCgroupHasController(virCgroupPtr cgroup, int controller); int virCgroupPathOfController(virCgroupPtr group, diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index be50f3e..e5190e3 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -198,7 +198,7 @@ testCgroupDetectMounts(const void *args) cleanup: VIR_FREE(mounts); VIR_FREE(parsed); - virCgroupFree(&group); + virCgroupFree(group); virBufferFreeAndReset(&buf); return result; } @@ -227,7 +227,7 @@ static int testCgroupNewForSelf(const void *args ATTRIB= UTE_UNUSED) ret =3D validateCgroup(cgroup, "", mountsFull, links, placement); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -304,7 +304,7 @@ static int testCgroupNewForPartition(const void *args A= TTRIBUTE_UNUSED) goto cleanup; } ret =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsSma= ll, links, placementSmall); - virCgroupFree(&cgroup); + virCgroupFree(cgroup); =20 if ((rv =3D virCgroupNewPartition("/virtualmachines", true, -1, &cgrou= p)) !=3D 0) { fprintf(stderr, "Cannot create /virtualmachines cgroup: %d\n", -rv= ); @@ -313,7 +313,7 @@ static int testCgroupNewForPartition(const void *args A= TTRIBUTE_UNUSED) ret =3D validateCgroup(cgroup, "/virtualmachines.partition", mountsFul= l, links, placementFull); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -353,7 +353,7 @@ static int testCgroupNewForPartitionNested(const void *= args ATTRIBUTE_UNUSED) } =20 /* Should now work */ - virCgroupFree(&cgroup); + virCgroupFree(cgroup); if ((rv =3D virCgroupNewPartition("/deployment/production", true, -1, = &cgroup)) !=3D 0) { fprintf(stderr, "Failed to create /deployment/production cgroup: %= d\n", -rv); goto cleanup; @@ -363,7 +363,7 @@ static int testCgroupNewForPartitionNested(const void *= args ATTRIBUTE_UNUSED) mountsFull, links, placementFull); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -402,14 +402,14 @@ static int testCgroupNewForPartitionNestedDeep(const = void *args ATTRIBUTE_UNUSED goto cleanup; } =20 - virCgroupFree(&cgroup); + virCgroupFree(cgroup); if ((rv =3D virCgroupNewPartition("/user/berrange.user", true, -1, &cg= roup)) !=3D 0) { fprintf(stderr, "Failed to create /user/berrange.user cgroup: %d\n= ", -rv); goto cleanup; } =20 /* Should now work */ - virCgroupFree(&cgroup); + virCgroupFree(cgroup); if ((rv =3D virCgroupNewPartition("/user/berrange.user/production", tr= ue, -1, &cgroup)) !=3D 0) { fprintf(stderr, "Failed to create /user/berrange.user/production c= group: %d\n", -rv); goto cleanup; @@ -419,7 +419,7 @@ static int testCgroupNewForPartitionNestedDeep(const vo= id *args ATTRIBUTE_UNUSED mountsFull, links, placementFull); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -455,8 +455,8 @@ static int testCgroupNewForPartitionDomain(const void *= args ATTRIBUTE_UNUSED) ret =3D validateCgroup(domaincgroup, "/production.partition/foo.libvir= t-lxc", mountsFull, links, placement); =20 cleanup: - virCgroupFree(&partitioncgroup); - virCgroupFree(&domaincgroup); + virCgroupFree(partitioncgroup); + virCgroupFree(domaincgroup); return ret; } =20 @@ -506,10 +506,10 @@ static int testCgroupNewForPartitionDomainEscaped(con= st void *args ATTRIBUTE_UNU ret =3D validateCgroup(domaincgroup, "/_cgroup.evil/net_cls.evil/__evi= l.evil/_cpu.foo.libvirt-lxc", mountsFull, links, placement); =20 cleanup: - virCgroupFree(&partitioncgroup3); - virCgroupFree(&partitioncgroup2); - virCgroupFree(&partitioncgroup1); - virCgroupFree(&domaincgroup); + virCgroupFree(partitioncgroup3); + virCgroupFree(partitioncgroup2); + virCgroupFree(partitioncgroup1); + virCgroupFree(domaincgroup); return ret; } =20 @@ -535,7 +535,7 @@ static int testCgroupNewForSelfAllInOne(const void *arg= s ATTRIBUTE_UNUSED) ret =3D validateCgroup(cgroup, "", mountsAllInOne, linksAllInOne, plac= ement); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -563,7 +563,7 @@ static int testCgroupNewForSelfLogind(const void *args = ATTRIBUTE_UNUSED) ret =3D validateCgroup(cgroup, "", mountsLogind, linksLogind, placemen= t); =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -690,7 +690,7 @@ static int testCgroupGetPercpuStats(const void *args AT= TRIBUTE_UNUSED) ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); VIR_FREE(params); return ret; } @@ -723,7 +723,7 @@ static int testCgroupGetMemoryUsage(const void *args AT= TRIBUTE_UNUSED) ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -773,7 +773,7 @@ static int testCgroupGetBlkioIoServiced(const void *arg= s ATTRIBUTE_UNUSED) ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 @@ -846,7 +846,7 @@ static int testCgroupGetBlkioIoDeviceServiced(const voi= d *args ATTRIBUTE_UNUSED) ret =3D 0; =20 cleanup: - virCgroupFree(&cgroup); + virCgroupFree(cgroup); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174861253692.2763118003705; Sat, 21 Jul 2018 05:07:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4598783F4C; Sat, 21 Jul 2018 12:07:39 +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 043BA308BDAC; Sat, 21 Jul 2018 12:07:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7139F4EE0B; Sat, 21 Jul 2018 12:07:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC7ZeG016169 for ; Sat, 21 Jul 2018 08:07:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id D2FA4600C6; Sat, 21 Jul 2018 12:07:35 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB970600C4 for ; Sat, 21 Jul 2018 12:07:33 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A6743680F for ; Sat, 21 Jul 2018 12:07:27 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id v13-v6so8966417pgr.10 for ; Sat, 21 Jul 2018 05:07:27 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=ugdp2hBqqb/kzWx1GI+cr3q7dMQAD1mZvmia3cjAzHk=; b=g+sfq8iTi6TwUWoNO6mFK2b2yTQNrBm7H/vownSABir+vyVKUPXmnDBnLjhuRB179l WEp+ogOJdz0gD71E8gJGQu5QA+R9TyyFzYbANC16cPv3P8F+nRxNEltDDTOw8/ap/APi v9t1YsNQaS0KqMO2FpwTCEvTgxKUNQ/P8jaAHYE4pgf0v+G3YTtnxgzbIkO7hWhpa5xI VPE/sylWJtymvijP965Ep/KDMwKIyoBYVNuzYvvTC9IgC3A7MUPMTzIR1TMOwBVGfkOp 9BJZ1764RkQCyYr8zASIaapVeJJ6THLJsQx6EPKW4zrCe5pRqNrROnG4WxpsMvhZ86cW q+rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ugdp2hBqqb/kzWx1GI+cr3q7dMQAD1mZvmia3cjAzHk=; b=bOD/vlwabUSGeFCfY+7G/OAM4JKeT236+agB9zIqJtn7yn9LPEqvBej+nQOt8hqJLa KJLrx51eWpFtJcCDe0qbfQW85Cuhi2HGfhbHXl6hiX668DyTKCCbHALQOMG0EqOuIXad rsPGO+3kPLiosSIHeuj+UeH4He2ODjQAzyHGeAIc9nV5Ju6mvMj6w6jdObTAvGxex3Lq QAe/kivFM7lA1KXl0d8/YWK6MftdeA4MS/4CFw+wCyTSjiLS8QKqaHoDMnRvPA2J6iUn gQTIPSidKYtdfFXFnqCjIqx3aPEikMCN883fKwHUA1nsDBkYb1Qipk0IAb6WooRCNHv7 AVTw== X-Gm-Message-State: AOUpUlFnH4fTxhe5E9N7MziIliSyvltzO+HBu4x9ZeXSFj+sXwSSiob7 spDgQx4mxpNNyHmzzSBRn9hxn+tc X-Google-Smtp-Source: AAOMgpdb+omDHivM2joeVceqaKxcp9eBhZWU6XxAjO8shsrA2nRwRC/7xDxTgkdpayFF7cFbjsfYrA== X-Received: by 2002:a62:d34a:: with SMTP id q71-v6mr5829655pfg.17.1532174846822; Sat, 21 Jul 2018 05:07:26 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:34 +0530 Message-Id: <1532174832-21644-3-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 21 Jul 2018 12:07:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 21 Jul 2018 12:07:27 +0000 (UTC) for IP:'209.85.215.195' DOMAIN:'mail-pg1-f195.google.com' HELO:'mail-pg1-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.215.195 mail-pg1-f195.google.com 209.85.215.195 mail-pg1-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 02/40] util: error: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 21 Jul 2018 12:07:40 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. The type virError and the declaration of virFreeError is done in include/libvirt/virterror.h which is pulled in by internal.h. When a variable of type virErrorPtr is declared using VIR_AUTOPTR, the function virFreeError will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virerror.c | 1 - src/util/virerror.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/virerror.c b/src/util/virerror.c index 5f26d59..4688e01 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -30,7 +30,6 @@ #include "virerror.h" #include "datatypes.h" #include "virlog.h" -#include "viralloc.h" #include "virthread.h" #include "virutil.h" #include "virstring.h" diff --git a/src/util/virerror.h b/src/util/virerror.h index 760bfa4..31577c5 100644 --- a/src/util/virerror.h +++ b/src/util/virerror.h @@ -23,6 +23,7 @@ # define __VIRT_ERROR_H_ =20 # include "internal.h" +# include "viralloc.h" =20 # define VIR_ERROR_MAX_LENGTH 1024 =20 @@ -205,4 +206,6 @@ bool virLastErrorIsSystemErrno(int errnum); void virErrorPreserveLast(virErrorPtr *saveerr); void virErrorRestore(virErrorPtr *savederr); =20 +VIR_DEFINE_AUTOPTR_FUNC(virError, virFreeError) + #endif --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174892863335.86224966745203; Sat, 21 Jul 2018 05:08:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E0C19308FB93; Sat, 21 Jul 2018 12:08:10 +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 A7FCC5B681; Sat, 21 Jul 2018 12:08:09 +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 64DB71841C5B; Sat, 21 Jul 2018 12:08:09 +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 w6LC7h96016200 for ; Sat, 21 Jul 2018 08:07:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id AEF4860E37; Sat, 21 Jul 2018 12:07:43 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9FBBC60C9A for ; Sat, 21 Jul 2018 12:07:40 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00B1F85540 for ; Sat, 21 Jul 2018 12:07:30 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id b17-v6so223058pfi.0 for ; Sat, 21 Jul 2018 05:07:29 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=uZ0oAEoHIK6dSJ6Du8S9vAeJp2QwsxsEJ1DCCj2E/l0=; b=m63ZfJI0GV4gXdnFV90FcIng6efOGok/XsnVWgYu3f0FhU81OV0H039us/9OuBtDoh WzkJPJntqzSFEOSC0fB12Yejo1s3oaKZmq34Pez/JblVP8nzNjMki1lm4GsiUS8BR1JA Yo5KXQn5SVYnFdN46sWW+VO2/W+hPscUiKFYpSt5qUpflfJzArD9sJCskn9RWdrcZ/UT sIhIvAX6l1eei/Vsq/2QiziPD90lB31MF2J8BJeAoYPkufckxvrEtNWt0x5pGmr4rKQm 9pTpxH8xyicPhfdbvTOJVisUcFs2wpqhNNouL7YNad3hcqydcStDcu9jdMD24XCWYHg0 prEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=uZ0oAEoHIK6dSJ6Du8S9vAeJp2QwsxsEJ1DCCj2E/l0=; b=LaloVVDqljoKivuDy9U8yD9MjVBpM2e5zorxNp7wpNQ1GiV1p4aM+wnZxYCWcNn+95 WhthuRKCckUxm7JZd0U0UWJBdtgXwigaPYIGVyGslcCFNdqDqcBF5w0EX50DutolgAEE Io3YSvkFGEqCvU/Im7qlU8mXCjPToTq7i4fu03ehPA14xhbEi54gC3Le3O8LoyAaskep XYu3G0+u+g4HlYyk23Y9u7gaIAMsS29Df/+qUbWfbXE2XP8j+Fv1GHLDMwX8KHyzzHtz ii4SMAStRTi7SLtZaQZzX3Lm3l/vaWkAzbUz3QYgJvCjHsa/IIay24Ac6peNNTwBQ1Ld 3UtA== X-Gm-Message-State: AOUpUlFkTjrqI0tiWbaY5DIDAaH6NMSQwx1yqnc8iaLX2r6robN15iKk aDWdBejmcgeFPBREHFC+BnrEHmpq X-Google-Smtp-Source: AAOMgpeHPBhut0dRn3Pmi2565osjHdtnoYpyveeLGWNNtOEJZ6ta4t7aCljaPSmSEapMpSqWuidLbw== X-Received: by 2002:a62:87ce:: with SMTP id i197-v6mr5881742pfe.62.1532174849276; Sat, 21 Jul 2018 05:07:29 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:35 +0530 Message-Id: <1532174832-21644-4-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 21 Jul 2018 12:07:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 21 Jul 2018 12:07:30 +0000 (UTC) for IP:'209.85.210.193' DOMAIN:'mail-pf1-f193.google.com' HELO:'mail-pf1-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.311 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, SPF_PASS, T_DKIM_INVALID) 209.85.210.193 mail-pf1-f193.google.com 209.85.210.193 mail-pf1-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 03/40] util: buffer: typedef and Free helper for struct _virBufferEscapePair 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Sat, 21 Jul 2018 12:08:11 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create typedefs virBufferEscapePair and virBufferEscapePairPtr for struct _virBufferEscapePair for cleaner code and for use with cleanup macros. Also create a dedicated Free helper virBufferEscapePairFree. Signed-off-by: Sukrit Bhatnagar --- src/util/virbuffer.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 3d6defb..8076cd3 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -648,11 +648,23 @@ virBufferEscape(virBufferPtr buf, char escape, const = char *toescape, } =20 =20 +typedef struct _virBufferEscapePair virBufferEscapePair; +typedef virBufferEscapePair *virBufferEscapePairPtr; + struct _virBufferEscapePair { char escape; char *toescape; }; =20 +static void +virBufferEscapePairFree(virBufferEscapePairPtr pair) +{ + if (!pair) + return; + + VIR_FREE(pair); +} + =20 /** * virBufferEscapeN: @@ -678,8 +690,8 @@ virBufferEscapeN(virBufferPtr buf, char *escaped =3D NULL; char *out; const char *cur; - struct _virBufferEscapePair escapeItem; - struct _virBufferEscapePair *escapeList =3D NULL; + virBufferEscapePair escapeItem; + virBufferEscapePairPtr escapeList =3D NULL; size_t nescapeList =3D 0; va_list ap; =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174890224411.1631660705; Sat, 21 Jul 2018 05:08:10 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9C767C04AC50; Sat, 21 Jul 2018 12:08:03 +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 5AEB35D9C9; Sat, 21 Jul 2018 12:08:02 +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 097404EE11; Sat, 21 Jul 2018 12:08:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC7kMK016212 for ; Sat, 21 Jul 2018 08:07:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 04E3F300193F; Sat, 21 Jul 2018 12:07:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F3098308332E for ; Sat, 21 Jul 2018 12:07:43 +0000 (UTC) Received: from mail-pl0-f50.google.com (mail-pl0-f50.google.com [209.85.160.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF137307D85D for ; Sat, 21 Jul 2018 12:07:32 +0000 (UTC) Received: by mail-pl0-f50.google.com with SMTP id 94-v6so6299532ple.12 for ; Sat, 21 Jul 2018 05:07:32 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=8mjgVQhARDH93FdVWk2/j7oiwNJ0sIyrrFGeuNrkibI=; b=Ev3qmByocawiAQKAEPXzsYo5boh7jYOvmhQUuUBj8tczAC20PhS8F8scS39H0to5cv UcgXOjC5THA7eWXYa1jRp4gdL3/lZpcgtuxk82FvD3I00axwS2zjSa8R9hv7nwzob+jN mN7Od0IaGjTA4avnuY6wZ/7bhF/bhvGLcDm0dcoRWknug5rfw6GjBuQTw4k02VWNOX5h HV5xmQSxHQbNLupw3dECf490EWVUkdl/UeNMcWdjeIDc2XadWW5prfUQZg8XLYoRkGrw 5C2pa6a/5dFBZEuAo5zQZqoO0MiVM5AFCt8xBXbDtg2NHGONI9cLae0PY2+HP6TNQrn7 Py9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=8mjgVQhARDH93FdVWk2/j7oiwNJ0sIyrrFGeuNrkibI=; b=csDWfdEzVI5MXx1FhymA87JZ6cEmdCGdUXShVQ6dTlZ1Z0IvPjOseSlY8/XfYwUwCT X4QHkvlYWSJt9WvmL4XVPq9wegxbx5qKzCEQYZZd4nkPtWUv98egjXQbT4eDUzvfb/Kl thM42wiyimSGkudGQ1rZAOGZLAfYAU3xb/5vMVVKLEqpLfz4sZ5xt28Wjg0bfTg7Ki7v LdW5GwhzM055R69OChhdFfxzTgMC68JNIXR7dcZewMf9TTQ3YPVnTTPS54MrkMkPUVq4 /eSuTYx0/2/FAdbjls4kDPVsWE7bywLkBeuLw8x1XE7D34+piL8RLv42PtfGq7huO2mf 4q7A== X-Gm-Message-State: AOUpUlE61Wm26igdfeG9u/cuLxydRDcNU2fkNIsfxtx3pBaPu3X8Nmwn G3Giq7f0/1/YS1IBf+bbukoWFf1n X-Google-Smtp-Source: AAOMgpeQ91AHnzMxAdpu0ihw2cSK2cTZOJ9rWIS5W25FtJp0YEJr0yjUsmMe5sakIYsNz3lhlyHdVA== X-Received: by 2002:a17:902:301:: with SMTP id 1-v6mr5594308pld.127.1532174852285; Sat, 21 Jul 2018 05:07:32 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:36 +0530 Message-Id: <1532174832-21644-5-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 21 Jul 2018 12:07:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 21 Jul 2018 12:07:33 +0000 (UTC) for IP:'209.85.160.50' DOMAIN:'mail-pl0-f50.google.com' HELO:'mail-pl0-f50.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.50 mail-pl0-f50.google.com 209.85.160.50 mail-pl0-f50.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 04/40] util: buffer: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 21 Jul 2018 12:08:09 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When variables of type virBufferPtr and virBufferEscapePairPtr are declared using VIR_AUTOPTR, the functions virBufferFreeAndReset and virBufferEscapePairFree, respectively, will be run automatically on them when they go out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virbuffer.c | 2 +- src/util/virbuffer.h | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 8076cd3..65f4a08 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -31,7 +31,6 @@ #define __VIR_BUFFER_C__ =20 #include "virbuffer.h" -#include "viralloc.h" #include "virerror.h" #include "virstring.h" =20 @@ -664,6 +663,7 @@ virBufferEscapePairFree(virBufferEscapePairPtr pair) =20 VIR_FREE(pair); } +VIR_DEFINE_AUTOPTR_FUNC(virBufferEscapePair, virBufferEscapePairFree) =20 =20 /** diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index e95ee87..3b31060 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -23,10 +23,13 @@ #ifndef __VIR_BUFFER_H__ # define __VIR_BUFFER_H__ =20 -# include "internal.h" - # include =20 +# include "internal.h" + +# include "viralloc.h" + + /** * virBuffer: * @@ -119,4 +122,6 @@ int virBufferGetIndent(const virBuffer *buf, bool dynam= ic); void virBufferTrim(virBufferPtr buf, const char *trim, int len); void virBufferAddStr(virBufferPtr buf, const char *str); =20 +VIR_DEFINE_AUTOPTR_FUNC(virBuffer, virBufferFreeAndReset) + #endif /* __VIR_BUFFER_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174912114617.170484427173; Sat, 21 Jul 2018 05:08:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFEBC308FB96; Sat, 21 Jul 2018 12:08:25 +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 91485C4A64; Sat, 21 Jul 2018 12:08:24 +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 4A79D1841C5B; Sat, 21 Jul 2018 12:08:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC7nsb016228 for ; Sat, 21 Jul 2018 08:07:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id DE4BCCC107; Sat, 21 Jul 2018 12:07:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D4B36CC105 for ; Sat, 21 Jul 2018 12:07:46 +0000 (UTC) Received: from mail-pl0-f67.google.com (mail-pl0-f67.google.com [209.85.160.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 540283DE33 for ; Sat, 21 Jul 2018 12:07:35 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id o7-v6so6297638plk.10 for ; Sat, 21 Jul 2018 05:07:35 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=RLdsn2/LzsUg73QWCsZsf7XsMUe9k6q02ynPV3VQ9fA=; b=YkVKsOuv8bjBOKArjkz6yk2LiydjKw2vlL8U5xGQMK/udVEEsDtukM8FTtuU0/hSlL IsQOZV4/lsuEnpOmuqZpA9n16Y65qDTKfPZ/3ecbEZA2n2WeXbgWZAIO5/jnUWFjwdyF CzOGRfmZg9I/1qvY2nlYHEZxnOxS3BPeI5J4K5lhVE7ih3+L8Fi+0MB9bWi2bGpWwmLW hsiRh1naLndQ5wirmgtID4+M3VEzpa/HBETHyHSuLkmeWlyxx6sWzLTzoyq+M/wsTO4I DP43CRehO/xPCcM2JGteauXn3IM6EW340GRYLbqFiT0MXGOIfdh2R0DZIIy1XVv3Tv7y +MoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=RLdsn2/LzsUg73QWCsZsf7XsMUe9k6q02ynPV3VQ9fA=; b=hjlZAXUBlb+D/TviiteE8o5SlteRQuuS/PH6XW4PcZg5zz3Hs1nvDM/KfOaQXee+Rn 59GGAtD0Ji6aNZ6ZXLsp+/8rklS55A1YbpBtFp68VLn0GERoB9GK4FK/eS8nvfKbAiTw 575lvJAi5hqmVvxQmu6CuxJB2SxSaljl0jSaCqjHadMHlPDKZvtSWPARTHgm64z8TEVk eOvDLPsHgn28Nx3LmSgc8YT2Om14XKefao2tHR+r7sPBr41vK9GUcoRAp90qdX2TcW66 +hX45mNGod7yi+Genh7pWlXC0VoH9HF36IU+l1fC2RH1bxNjejcnZl5S10FL5sqvsTTT VTkA== X-Gm-Message-State: AOUpUlEWF9MlMHzLKj8VgMdLHRrxe1mC2JUNF7d1KteeUQ3VEFm7IYqx qKLgLymTmzSO0ffPvIpaza60V6db X-Google-Smtp-Source: AAOMgpesKLIfC9Jlry6sk90mq/yWMvkPp8V+9hmP8MBWqZEtUdmfMSX2XIt0lUZybl1asqKMKHElJw== X-Received: by 2002:a17:902:7b96:: with SMTP id w22-v6mr5674890pll.24.1532174854622; Sat, 21 Jul 2018 05:07:34 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:37 +0530 Message-Id: <1532174832-21644-6-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 21 Jul 2018 12:07:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 21 Jul 2018 12:07:35 +0000 (UTC) for IP:'209.85.160.67' DOMAIN:'mail-pl0-f67.google.com' HELO:'mail-pl0-f67.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.67 mail-pl0-f67.google.com 209.85.160.67 mail-pl0-f67.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 05/40] util: buffer: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Sat, 21 Jul 2018 12:08:31 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virbuffer.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 65f4a08..a35feb6 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -455,7 +455,8 @@ void virBufferEscapeString(virBufferPtr buf, const char *format, const char *st= r) { int len; - char *escaped, *out; + VIR_AUTOFREE(char *) escaped =3D NULL; + char *out; const char *cur; const char forbidden_characters[] =3D { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, @@ -532,7 +533,6 @@ virBufferEscapeString(virBufferPtr buf, const char *for= mat, const char *str) *out =3D 0; =20 virBufferAsprintf(buf, format, escaped); - VIR_FREE(escaped); } =20 /** @@ -611,7 +611,8 @@ virBufferEscape(virBufferPtr buf, char escape, const ch= ar *toescape, const char *format, const char *str) { int len; - char *escaped, *out; + VIR_AUTOFREE(char *) escaped =3D NULL; + char *out; const char *cur; =20 if ((format =3D=3D NULL) || (buf =3D=3D NULL) || (str =3D=3D NULL)) @@ -643,7 +644,6 @@ virBufferEscape(virBufferPtr buf, char escape, const ch= ar *toescape, *out =3D 0; =20 virBufferAsprintf(buf, format, escaped); - VIR_FREE(escaped); } =20 =20 @@ -687,7 +687,7 @@ virBufferEscapeN(virBufferPtr buf, { int len; size_t i; - char *escaped =3D NULL; + VIR_AUTOFREE(char *) escaped =3D NULL; char *out; const char *cur; virBufferEscapePair escapeItem; @@ -750,7 +750,6 @@ virBufferEscapeN(virBufferPtr buf, cleanup: va_end(ap); VIR_FREE(escapeList); - VIR_FREE(escaped); } =20 =20 @@ -815,7 +814,8 @@ void virBufferEscapeShell(virBufferPtr buf, const char *str) { int len; - char *escaped, *out; + VIR_AUTOFREE(char *) escaped =3D NULL; + char *out; const char *cur; =20 if ((buf =3D=3D NULL) || (str =3D=3D NULL)) @@ -859,7 +859,6 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) *out =3D 0; =20 virBufferAdd(buf, escaped, -1); - VIR_FREE(escaped); } =20 /** --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174931070215.14254351403736; Sat, 21 Jul 2018 05:08:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D64AC0587DA; Sat, 21 Jul 2018 12:08:49 +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 678833001A49; Sat, 21 Jul 2018 12:08: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 0E0754EE12; Sat, 21 Jul 2018 12:08:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC7pfi016243 for ; Sat, 21 Jul 2018 08:07:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id E4B8F308BDAD; Sat, 21 Jul 2018 12:07:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D9A7A308BDAC for ; Sat, 21 Jul 2018 12:07:49 +0000 (UTC) Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDD80C057F9F for ; Sat, 21 Jul 2018 12:07:37 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id e6-v6so8968441pgv.2 for ; Sat, 21 Jul 2018 05:07:37 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=yo9AzSl78ghpflUxtPWSJMsWbWipWcUIKLrIkzOGHXw=; b=OT6+K25I/B/nwLVnWODOA2vXs7+fPQDZ0Su4XqqYAD6y+WLw20kAUIwbyEcFFMMYXj DDqinyih69zN49uq1jNlArWlgnLRVhlz/LkZOl5nzpNCfYx/gwmhg9bIhb3Q9EkBk2Vq vsTWe7T3/0KJukM7qm7AAFF5G+Eh0VimTMtRByD75xqu6ZnTO8WVwRQYP/9UnSGqL0QS 7Cj5igjfVv85t9PSDvAsVXHX9dLQDkl542xjfizT39/DO6zJzYdvmQrnzw//JBo49Qq7 1dzdYb0wHKcOmprlz/h0KXpRUOLS+chNbGQMMMdOFK2X3QAiBWoKUDDnjbLAScv9KYkr i05g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=yo9AzSl78ghpflUxtPWSJMsWbWipWcUIKLrIkzOGHXw=; b=iUsUilpZzNUg/QJNDm0XPFh3QwNcgDr4dzUo6kNyqy/w18SJ3CunUVSFumfszlgJPU 6WQgs+KAlZdNQQDuUnYsXnIQc3UHE2PY0RquKrit3hJNNOx0HHPfR2iEXjd0OODXkIEN TdziRUpJW802u7EmLQUMaUL+j3WkD7jt8CKnYMjaxwYw5pxdUnDxkqR2lf9+nR45vBuL f6BMBvGSplLTPeaWlJn3gHVa2vtFqpjiEC+XAlTYc6TjRoe/MyuAXmtKArG72L5vAJBv v2YiKTwi+goFmavBpVLmrdmwwFgzENNasdc93IcOFN4AyZj2oYnXs2eI/8LaVMLhOepC 11Nw== X-Gm-Message-State: AOUpUlHzX6g+Bfq79VKsk01nfFGRQh2FHbTTsqdv96K9I02ELLDd5zZg BXuNcetKxXcBo7udVInNWFOVh2q/ X-Google-Smtp-Source: AAOMgpe4u8WFzoNWV8DPlvE1qkWrECSOVvjeC0+EtZL2loZXjVwnr/P/XtPtCwnMQNHLO2tK3gPFOw== X-Received: by 2002:a63:1644:: with SMTP id 4-v6mr5538024pgw.103.1532174857269; Sat, 21 Jul 2018 05:07:37 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:38 +0530 Message-Id: <1532174832-21644-7-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:07:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:07:38 +0000 (UTC) for IP:'209.85.215.169' DOMAIN:'mail-pg1-f169.google.com' HELO:'mail-pg1-f169.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.169 mail-pg1-f169.google.com 209.85.215.169 mail-pg1-f169.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 06/40] util: buffer: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:08:50 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virbuffer.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index a35feb6..d2827f6 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -691,7 +691,7 @@ virBufferEscapeN(virBufferPtr buf, char *out; const char *cur; virBufferEscapePair escapeItem; - virBufferEscapePairPtr escapeList =3D NULL; + VIR_AUTOPTR(virBufferEscapePair) escapeList =3D NULL; size_t nescapeList =3D 0; va_list ap; =20 @@ -749,7 +749,6 @@ virBufferEscapeN(virBufferPtr buf, =20 cleanup: va_end(ap); - VIR_FREE(escapeList); } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174889098909.3846204527616; Sat, 21 Jul 2018 05:08:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 720F2C057FA3; Sat, 21 Jul 2018 12:08:02 +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 3F0FB5B681; Sat, 21 Jul 2018 12:08:02 +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 ECC151841C57; Sat, 21 Jul 2018 12:08:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC7pKL016236 for ; Sat, 21 Jul 2018 08:07:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5D3C55B680; Sat, 21 Jul 2018 12:07:51 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5658E5D6B4 for ; Sat, 21 Jul 2018 12:07:51 +0000 (UTC) Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2DE81C057FA1 for ; Sat, 21 Jul 2018 12:07:40 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id y4-v6so8959811pgp.9 for ; Sat, 21 Jul 2018 05:07:40 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=y79XWLHUnzzA+oPkO4cgu9EbTVS03ReX35qhgpdUprc=; b=Lpn2etqn4cEWQd51IosHL0kY8YcyQys2qH6g0NtPCMWX5i7cPQMcNt40x7+VnbA8xc ol0j/OcDKBbjm+9MLOheNR4NJGvblcucLcTofQZOkdWQahBoEWMH4aisGMKhQQsfQzUR nlGfWFZrI0LG2hKvQzFkWZS5zbU79e8IlkqMWATvHDA9++sTZOkVfPrJd0XUOPCf7fDX hxRqAXut3rD1M0aIP/FwdKCeOQOwmOEvvqWY5Dr3TDHUGvGpGRPO4NnSDtPgtvJIjaFk y2z8fY2Y+B0WQc/3Y9qQcCiEh/oEmdiGzxjSdJQNP03RbkIvaFAXbmo7gua9DCXf0lAO awdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=y79XWLHUnzzA+oPkO4cgu9EbTVS03ReX35qhgpdUprc=; b=OBifeK8AqMWXROEPWiseEd1W65PUGOPgFkvV7CtqoB8qOG1OE4LeLpQSra7fUmAiao CezgUyb/Qy6mYzE7Vbf8kFGw3RlVCRrD4d2+JPXjhG6UI1ZO1ZqZeGIGdlOytaqru2UN BNlRpYcM8uvNssXelliFLBALLnsVmpb5aF4Z0FTo2n2sMfWEpYBQXnKpnsEzoHQgi77z lKmO0AMdwLzw1T4PnbjLiT2x1XnmSqHVxrLObX2CPHqssiKL5i+MxCfU+uz5YRr8a79t KD+riZOB8RboWLOZqAkPi2H0h4TTwVJ1UVJFQU0nGXkf5aKOClLFLu8sYMgR5t1uDkid M97g== X-Gm-Message-State: AOUpUlErSDqlmUeLQAYDIFGmPcbJMemDdsOncRxseIxGyGmBaKTu2sGT /V7qoWIEnk/JFSoxlF7HvXtGvSNj X-Google-Smtp-Source: AAOMgpdhPndrs8CsiE4VQgtgXzUxW661MSFNc/PTRzz9CN8ZNH1xuXoAaCG2ZZKIu9MYSN45/7362A== X-Received: by 2002:a65:5307:: with SMTP id m7-v6mr5543597pgq.431.1532174859463; Sat, 21 Jul 2018 05:07:39 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:39 +0530 Message-Id: <1532174832-21644-8-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:07:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:07:40 +0000 (UTC) for IP:'209.85.215.173' DOMAIN:'mail-pg1-f173.google.com' HELO:'mail-pg1-f173.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.173 mail-pg1-f173.google.com 209.85.215.173 mail-pg1-f173.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 07/40] util: hash: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:08:08 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When variables of type virHashTablePtr are declared using VIR_AUTOPTR, the function virHashFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virhash.c | 1 - src/util/virhash.h | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/virhash.c b/src/util/virhash.c index ecda55d..006ffd8 100644 --- a/src/util/virhash.c +++ b/src/util/virhash.c @@ -26,7 +26,6 @@ =20 #include "virerror.h" #include "virhash.h" -#include "viralloc.h" #include "virlog.h" #include "virhashcode.h" #include "virrandom.h" diff --git a/src/util/virhash.h b/src/util/virhash.h index 5b24fc0..dd789c6 100644 --- a/src/util/virhash.h +++ b/src/util/virhash.h @@ -16,6 +16,8 @@ # include # include =20 +# include "viralloc.h" + /* * The hash table. */ @@ -200,4 +202,6 @@ void *virHashSearch(const virHashTable *table, virHashS= earcher iter, /* Convenience for when VIR_FREE(value) is sufficient as a data freer. */ void virHashValueFree(void *value, const void *name); =20 +VIR_DEFINE_AUTOPTR_FUNC(virHashTable, virHashFree) + #endif /* ! __VIR_HASH_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153217491618672.30141807500115; Sat, 21 Jul 2018 05:08:36 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1944182BD; Sat, 21 Jul 2018 12:08:31 +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 DDFE9101F97D; Sat, 21 Jul 2018 12:08:29 +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 9DD901841C5B; Sat, 21 Jul 2018 12:08:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC7uNf016259 for ; Sat, 21 Jul 2018 08:07:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9717A4C7; Sat, 21 Jul 2018 12:07:56 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C9DC5C20D for ; Sat, 21 Jul 2018 12:07:53 +0000 (UTC) Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42CA4307D86F for ; Sat, 21 Jul 2018 12:07:42 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id k3-v6so8966694pgq.5 for ; Sat, 21 Jul 2018 05:07:42 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.39 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=eE7++OVFKIcNNFP2cmes4k42Hlg86MdnfePZfSf+7BI=; b=mOlHKNJWJksVWdoh4EI8+pCqOOFcEsNGb1rGdgY8eV1jwg1jUTpduyyMkXy2ZCKTvi NOESAfYoYRYzvI7cJuvqCUkI5OkJEhywbolKb/vueWzNK8fHc6I5kj7q8QNETTeRdcxl Baiw3nz0XosqJY2DogwEDrTLvkM9g7t18ns/JC+JBEHCdWxo2CrNuS67kzslHKD1k+Fi Yjwhqww957uoc35H/da5nRnJuw4p3eprEiLDCknICKwlYkAizx46bCfjeXH6mfR4egBe mIbJ06RIlfojc7+eZxQLQ4CcKuq9napgmy4hKOfOR8Fl190hvRnh5yO7MDii+70CfiKd nlHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=eE7++OVFKIcNNFP2cmes4k42Hlg86MdnfePZfSf+7BI=; b=n2nFiVHZfteYgfwOPlw5E3uwdOkptAVMGrF/IT8LX1i7tjcdPequ5c5LHLrcBtnEEq W5VQk86SaVaCBSiCWrQ2y+QuWCFmcbj1KvOjUtfP9AC0NnSYFWi2lZfwoB4hJaRPW7Hs YBdRjjWQv15wvEH+F29wi+guCJ9LULxYu7d2l1lyKePovNxE6v9/cVZjoD8H1WpRYlEy obNQl+VbDIkex1Z1EEYU2QzHr83dEOD3/qP/N6L9zfDsuXp2G4IRRkHsZtDvBo+pUN5z QveiN4FH8TIPzvPFu4U+YRzuUfkkeooCt1JGV8eugD9f+NV/Qfm7g8rficm+guKDTY82 13Ow== X-Gm-Message-State: AOUpUlG6HM3+u8VTRRI8+1tYMSf4EMvnpeDkFDRD536Rwi0SOGZaE/lj 2UxBJejkBlWSuGHWubPPvaD57wrx X-Google-Smtp-Source: AAOMgpdVQ5k+QSgNYHw+Myx62rJtOvqUwai56xXfhZRCUptjHbJTNwMda+iBi/N8F7/wHINUos4IdQ== X-Received: by 2002:a63:735d:: with SMTP id d29-v6mr5501981pgn.156.1532174861562; Sat, 21 Jul 2018 05:07:41 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:40 +0530 Message-Id: <1532174832-21644-9-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 21 Jul 2018 12:07:42 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 21 Jul 2018 12:07:42 +0000 (UTC) for IP:'209.85.215.173' DOMAIN:'mail-pg1-f173.google.com' HELO:'mail-pg1-f173.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.173 mail-pg1-f173.google.com 209.85.215.173 mail-pg1-f173.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 08/40] util: cgroup: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 21 Jul 2018 12:08:35 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virCgroupPtr is declared using VIR_AUTOPTR, the function virCgroupFree will be run automatically on it when it goes out of scope. This commit also adds an intermediate typedef for virCgroup type for use with the cleanup macros by renaming the struct in src/util/vircgrouppriv.h from virCgroup to _virCgroup. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/vircgroup.c | 1 - src/util/vircgroup.h | 9 +++++++-- src/util/vircgrouppriv.h | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 140b016..bc5f774 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -50,7 +50,6 @@ #include "vircgrouppriv.h" =20 #include "virutil.h" -#include "viralloc.h" #include "virerror.h" #include "virlog.h" #include "virfile.h" diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h index e4ffd57..065861d 100644 --- a/src/util/vircgroup.h +++ b/src/util/vircgroup.h @@ -27,9 +27,11 @@ =20 # include "virutil.h" # include "virbitmap.h" +# include "viralloc.h" =20 -struct virCgroup; -typedef struct virCgroup *virCgroupPtr; +struct _virCgroup; +typedef struct _virCgroup virCgroup; +typedef virCgroup *virCgroupPtr; =20 enum { VIR_CGROUP_CONTROLLER_CPU, @@ -297,4 +299,7 @@ int virCgroupSetOwner(virCgroupPtr cgroup, int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller); =20 bool virCgroupControllerAvailable(int controller); + +VIR_DEFINE_AUTOPTR_FUNC(virCgroup, virCgroupFree) + #endif /* __VIR_CGROUP_H__ */ diff --git a/src/util/vircgrouppriv.h b/src/util/vircgrouppriv.h index 722863e..a72bee1 100644 --- a/src/util/vircgrouppriv.h +++ b/src/util/vircgrouppriv.h @@ -42,7 +42,7 @@ struct virCgroupController { char *placement; }; =20 -struct virCgroup { +struct _virCgroup { char *path; =20 struct virCgroupController controllers[VIR_CGROUP_CONTROLLER_LAST]; --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174907592830.0395639658855; Sat, 21 Jul 2018 05:08:27 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 59DEDC04B302; Sat, 21 Jul 2018 12:08:26 +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 1242160C8F; Sat, 21 Jul 2018 12:08:26 +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 B93664EE0B; Sat, 21 Jul 2018 12:08:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC7wG3016269 for ; Sat, 21 Jul 2018 08:07:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 521B74C7; Sat, 21 Jul 2018 12:07:58 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45FD85C20D for ; Sat, 21 Jul 2018 12:07:58 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B838485A02 for ; Sat, 21 Jul 2018 12:07:45 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id f1-v6so8956293pgq.12 for ; Sat, 21 Jul 2018 05:07:45 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Zz7gz/k8sONsWlKvnEw6H1bkW/q7juOD/NWYwiSyArU=; b=jo0GRyKHH4b7UvP/0LjYLinofZ4kuoq1f2gYVdgTupqlbz+ukycK+J26q9NmWQDxDY W/DyKK9Xb0/agxTgWRx9p2pxkI0btYnUNxiOMITdscRdULXkhl3QC3ZLEYsdiZfsm09K Hv4YPogQxu6PpSNKVXU+7yDkKbiPSamEyD5QJlYebJjI7FXp8gMUQRtatEOrV7LSuk+S 5Nq72jTbKLouwh8S/tMqZtaoiY73lWetJ/jXiTJLArkt2hloUxGfK1X9kYytqfPocr66 3orfNdR7m+KRAzSfzu/SQA+ucVujlOhpxFRerV9zS4IJNWVjAEQ13edRP0KfwV8QIJ84 Rqrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Zz7gz/k8sONsWlKvnEw6H1bkW/q7juOD/NWYwiSyArU=; b=gJ19jD/cP4MjolyArO8f+OH88d6OLmQuPga9cohvamwXz72C7aUvN3zRwwHSFSn9fX dlRyEkb11TMu4i6tufl435aZDDZqC8hfTJj7fSENf/4msxepSz/mZk2AhsxyukcEzH/S TVv5uuOdnm9hwlKoOUqBq5pB0wsT0e0o7rTxGqmXjxP7JOPjb2epwNoUh43WtrnlJJ7X om/Lm2fVhgD4yc5+pPzKvmsKEh+iXsGJr/IJeb8zbpA138KmZHKwlQwOz/tWPOlsZSY4 KDGE56k1Bv7J15wPR4r+NHkxqR4fFw8k9ArUXdmz4tTE96XclxOFLzt+xc+z/Q0ummxO b/vw== X-Gm-Message-State: AOUpUlEhmDLKrGg1ZY6+PD7o2DV7loHnq/Jcv/AkYTn/nHtzYdqEdnuT 0wpHhBkG7xgmdZmeDxQ6CKLBTjW8 X-Google-Smtp-Source: AAOMgpegvaZeLfvlJQlO7sOZFcE9Tp/30r055VFIUSXZohBmOFCUk/sPCKpGr189Sg+q4S2u2oakPw== X-Received: by 2002:a63:dc17:: with SMTP id s23-v6mr5597446pgg.40.1532174864501; Sat, 21 Jul 2018 05:07:44 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:41 +0530 Message-Id: <1532174832-21644-10-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:07:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:07:45 +0000 (UTC) for IP:'209.85.215.194' DOMAIN:'mail-pg1-f194.google.com' HELO:'mail-pg1-f194.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.194 mail-pg1-f194.google.com 209.85.215.194 mail-pg1-f194.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 09/40] util: cgroup: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 21 Jul 2018 12:08:26 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/vircgroup.c | 528 ++++++++++++++++++-----------------------------= ---- 1 file changed, 181 insertions(+), 347 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index bc5f774..4bb4408 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -162,7 +162,7 @@ virCgroupPartitionNeedsEscaping(const char *path) { FILE *fp =3D NULL; int ret =3D 0; - char *line =3D NULL; + VIR_AUTOFREE(char *) line =3D NULL; size_t buflen; =20 /* If it starts with 'cgroup.' or a '_' of any @@ -222,7 +222,6 @@ virCgroupPartitionNeedsEscaping(const char *path) } =20 cleanup: - VIR_FREE(line); VIR_FORCE_FCLOSE(fp); return ret; } @@ -255,41 +254,40 @@ virCgroupValidateMachineGroup(virCgroupPtr group, const char *machinename) { size_t i; - bool valid =3D false; - char *partname =3D NULL; - char *scopename_old =3D NULL; - char *scopename_new =3D NULL; - char *partmachinename =3D NULL; + VIR_AUTOFREE(char *) partname =3D NULL; + VIR_AUTOFREE(char *) scopename_old =3D NULL; + VIR_AUTOFREE(char *) scopename_new =3D NULL; + VIR_AUTOFREE(char *) partmachinename =3D NULL; =20 if (virAsprintf(&partname, "%s.libvirt-%s", name, drivername) < 0) - goto cleanup; + return false; =20 if (virCgroupPartitionEscape(&partname) < 0) - goto cleanup; + return false; =20 if (machinename && (virAsprintf(&partmachinename, "%s.libvirt-%s", machinename, drivername) < 0 || virCgroupPartitionEscape(&partmachinename) < 0)) - goto cleanup; + return false; =20 if (!(scopename_old =3D virSystemdMakeScopeName(name, drivername, true= ))) - goto cleanup; + return false; =20 /* We should keep trying even if this failed */ if (!machinename) virResetLastError(); else if (!(scopename_new =3D virSystemdMakeScopeName(machinename, drivername, false))) - goto cleanup; + return false; =20 if (virCgroupPartitionEscape(&scopename_old) < 0) - goto cleanup; + return false; =20 if (scopename_new && virCgroupPartitionEscape(&scopename_new) < 0) - goto cleanup; + return false; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { char *tmp; @@ -302,7 +300,7 @@ virCgroupValidateMachineGroup(virCgroupPtr group, =20 tmp =3D strrchr(group->controllers[i].placement, '/'); if (!tmp) - goto cleanup; + return false; =20 if (stripEmulatorSuffix && (i =3D=3D VIR_CGROUP_CONTROLLER_CPU || @@ -312,7 +310,7 @@ virCgroupValidateMachineGroup(virCgroupPtr group, *tmp =3D '\0'; tmp =3D strrchr(group->controllers[i].placement, '/'); if (!tmp) - goto cleanup; + return false; } =20 tmp++; @@ -328,18 +326,11 @@ virCgroupValidateMachineGroup(virCgroupPtr group, tmp, virCgroupControllerTypeToString(i), name, NULLSTR(machinename), partname, scopename_old, NULLSTR(scopename_new)); - goto cleanup; + return false; } } =20 - valid =3D true; - - cleanup: - VIR_FREE(partmachinename); - VIR_FREE(partname); - VIR_FREE(scopename_old); - VIR_FREE(scopename_new); - return valid; + return true; } =20 =20 @@ -377,7 +368,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, FILE *mounts =3D NULL; struct mntent entry; char buf[CGROUP_MAX_VAL]; - char *linksrc =3D NULL; int ret =3D -1; =20 mounts =3D fopen(path, "r"); @@ -432,8 +422,9 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, /* If it is a co-mount it has a filename like "cpu,cpu= acct" * and we must identify the symlink path */ if (checkLinks && strchr(tmp2 + 1, ',')) { + VIR_AUTOFREE(char *) linksrc =3D NULL; + *tmp2 =3D '\0'; - VIR_FREE(linksrc); if (virAsprintf(&linksrc, "%s/%s", entry.mnt_dir, typestr) < 0) goto cleanup; @@ -467,7 +458,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, =20 ret =3D 0; cleanup: - VIR_FREE(linksrc); VIR_FORCE_FCLOSE(mounts); return ret; } @@ -546,7 +536,7 @@ virCgroupDetectPlacement(virCgroupPtr group, FILE *mapping =3D NULL; char line[1024]; int ret =3D -1; - char *procfile; + VIR_AUTOFREE(char *) procfile =3D NULL; =20 VIR_DEBUG("Detecting placement for pid %lld path %s", (long long) pid, path); @@ -627,9 +617,7 @@ virCgroupDetectPlacement(virCgroupPtr group, ret =3D 0; =20 cleanup: - VIR_FREE(procfile); VIR_FORCE_FCLOSE(mapping); - return ret; } =20 @@ -785,8 +773,7 @@ virCgroupSetValueStr(virCgroupPtr group, const char *key, const char *value) { - int ret =3D -1; - char *keypath =3D NULL; + VIR_AUTOFREE(char *) keypath =3D NULL; char *tmp =3D NULL; =20 if (virCgroupPathOfController(group, controller, key, &keypath) < 0) @@ -799,18 +786,14 @@ virCgroupSetValueStr(virCgroupPtr group, virReportSystemError(errno, _("Invalid value '%s' for '%s'"), value, tmp + 1); - goto cleanup; + return -1; } virReportSystemError(errno, _("Unable to write to '%s'"), keypath); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(keypath); - return ret; + return 0; } =20 =20 @@ -820,8 +803,8 @@ virCgroupGetValueStr(virCgroupPtr group, const char *key, char **value) { - char *keypath =3D NULL; - int ret =3D -1, rc; + VIR_AUTOFREE(char *) keypath =3D NULL; + int rc; =20 *value =3D NULL; =20 @@ -833,18 +816,14 @@ virCgroupGetValueStr(virCgroupPtr group, if ((rc =3D virFileReadAll(keypath, 1024*1024, value)) < 0) { virReportSystemError(errno, _("Unable to read from '%s'"), keypath); - goto cleanup; + return -1; } =20 /* Terminated with '\n' has sometimes harmful effects to the caller */ if (rc > 0 && (*value)[rc - 1] =3D=3D '\n') (*value)[rc - 1] =3D '\0'; =20 - ret =3D 0; - - cleanup: - VIR_FREE(keypath); - return ret; + return 0; } =20 =20 @@ -855,8 +834,8 @@ virCgroupGetValueForBlkDev(virCgroupPtr group, const char *path, char **value) { - char *prefix =3D NULL; - char *str =3D NULL; + VIR_AUTOFREE(char *) prefix =3D NULL; + VIR_AUTOFREE(char *) str =3D NULL; char **lines =3D NULL; int ret =3D -1; =20 @@ -874,8 +853,6 @@ virCgroupGetValueForBlkDev(virCgroupPtr group, =20 ret =3D 0; error: - VIR_FREE(str); - VIR_FREE(prefix); virStringListFree(lines); return ret; } @@ -887,17 +864,12 @@ virCgroupSetValueU64(virCgroupPtr group, const char *key, unsigned long long int value) { - char *strval =3D NULL; - int ret; + VIR_AUTOFREE(char *) strval =3D NULL; =20 if (virAsprintf(&strval, "%llu", value) < 0) return -1; =20 - ret =3D virCgroupSetValueStr(group, controller, key, strval); - - VIR_FREE(strval); - - return ret; + return virCgroupSetValueStr(group, controller, key, strval); } =20 =20 @@ -907,17 +879,12 @@ virCgroupSetValueI64(virCgroupPtr group, const char *key, long long int value) { - char *strval =3D NULL; - int ret; + VIR_AUTOFREE(char *) strval =3D NULL; =20 if (virAsprintf(&strval, "%lld", value) < 0) return -1; =20 - ret =3D virCgroupSetValueStr(group, controller, key, strval); - - VIR_FREE(strval); - - return ret; + return virCgroupSetValueStr(group, controller, key, strval); } =20 =20 @@ -927,24 +894,19 @@ virCgroupGetValueI64(virCgroupPtr group, const char *key, long long int *value) { - char *strval =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) strval =3D NULL; =20 if (virCgroupGetValueStr(group, controller, key, &strval) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ll(strval, NULL, 10, value) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), strval); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(strval); - return ret; + return 0; } =20 =20 @@ -954,24 +916,19 @@ virCgroupGetValueU64(virCgroupPtr group, const char *key, unsigned long long int *value) { - char *strval =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) strval =3D NULL; =20 if (virCgroupGetValueStr(group, controller, key, &strval) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ull(strval, NULL, 10, value) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), strval); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(strval); - return ret; + return 0; } =20 =20 @@ -987,7 +944,7 @@ virCgroupCpuSetInherit(virCgroupPtr parent, virCgroupPt= r group) =20 VIR_DEBUG("Setting up inheritance %s -> %s", parent->path, group->path= ); for (i =3D 0; i < ARRAY_CARDINALITY(inherit_values); i++) { - char *value; + VIR_AUTOFREE(char *) value =3D NULL; =20 if (virCgroupGetValueStr(parent, VIR_CGROUP_CONTROLLER_CPUSET, @@ -1000,11 +957,8 @@ virCgroupCpuSetInherit(virCgroupPtr parent, virCgroup= Ptr group) if (virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_CPUSET, inherit_values[i], - value) < 0) { - VIR_FREE(value); + value) < 0) return -1; - } - VIR_FREE(value); } =20 return 0; @@ -1043,11 +997,10 @@ virCgroupMakeGroup(virCgroupPtr parent, unsigned int flags) { size_t i; - int ret =3D -1; =20 VIR_DEBUG("Make group %s", group->path); for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; =20 /* We must never mkdir() in systemd's hierarchy */ if (i =3D=3D VIR_CGROUP_CONTROLLER_SYSTEMD) { @@ -1073,10 +1026,8 @@ virCgroupMakeGroup(virCgroupPtr parent, if (!virFileExists(path)) { if (!create || mkdir(path, 0755) < 0) { - if (errno =3D=3D EEXIST) { - VIR_FREE(path); + if (errno =3D=3D EEXIST) continue; - } /* With a kernel that doesn't support multi-level directory * for blkio controller, libvirt will fail and disable all * other controllers even though they are available. So @@ -1084,24 +1035,20 @@ virCgroupMakeGroup(virCgroupPtr parent, if (i =3D=3D VIR_CGROUP_CONTROLLER_BLKIO) { VIR_DEBUG("Ignoring mkdir failure with blkio controlle= r. Kernel probably too old"); VIR_FREE(group->controllers[i].mountPoint); - VIR_FREE(path); continue; } else { virReportSystemError(errno, _("Failed to create controller %s= for group"), virCgroupControllerTypeToString(i= )); - VIR_FREE(path); - goto cleanup; + return -1; } } if (group->controllers[VIR_CGROUP_CONTROLLER_CPUSET].mountPoin= t !=3D NULL && (i =3D=3D VIR_CGROUP_CONTROLLER_CPUSET || STREQ(group->controllers[i].mountPoint, group->controllers[VIR_CGROUP_CONTROLLER_CPUSET].mo= untPoint))) { - if (virCgroupCpuSetInherit(parent, group) < 0) { - VIR_FREE(path); - goto cleanup; - } + if (virCgroupCpuSetInherit(parent, group) < 0) + return -1; } /* * Note that virCgroupSetMemoryUseHierarchy should always be @@ -1112,21 +1059,14 @@ virCgroupMakeGroup(virCgroupPtr parent, (i =3D=3D VIR_CGROUP_CONTROLLER_MEMORY || STREQ(group->controllers[i].mountPoint, group->controllers[VIR_CGROUP_CONTROLLER_MEMORY].mo= untPoint))) { - if (virCgroupSetMemoryUseHierarchy(group) < 0) { - VIR_FREE(path); - goto cleanup; - } + if (virCgroupSetMemoryUseHierarchy(group) < 0) + return -1; } } - - VIR_FREE(path); } =20 VIR_DEBUG("Done making controllers for group"); - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -1338,9 +1278,9 @@ virCgroupNewPartition(const char *path, virCgroupPtr *group) { int ret =3D -1; - char *parentPath =3D NULL; + VIR_AUTOFREE(char *) parentPath =3D NULL; + VIR_AUTOFREE(char *) newPath =3D NULL; virCgroupPtr parent =3D NULL; - char *newPath =3D NULL; VIR_DEBUG("path=3D%s create=3D%d controllers=3D%x", path, create, controllers); =20 @@ -1380,8 +1320,6 @@ virCgroupNewPartition(const char *path, if (ret !=3D 0) virCgroupFree(*group); virCgroupFree(parent); - VIR_FREE(parentPath); - VIR_FREE(newPath); return ret; } =20 @@ -1420,18 +1358,17 @@ virCgroupNewDomainPartition(virCgroupPtr partition, bool create, virCgroupPtr *group) { - int ret =3D -1; - char *grpname =3D NULL; + VIR_AUTOFREE(char *)grpname =3D NULL; =20 if (virAsprintf(&grpname, "%s.libvirt-%s", name, driver) < 0) - goto cleanup; + return -1; =20 if (virCgroupPartitionEscape(&grpname) < 0) - goto cleanup; + return -1; =20 if (virCgroupNew(-1, grpname, partition, -1, group) < 0) - goto cleanup; + return -1; =20 /* * Create a cgroup with memory.use_hierarchy enabled to @@ -1447,14 +1384,10 @@ virCgroupNewDomainPartition(virCgroupPtr partition, VIR_CGROUP_MEM_HIERACHY) < 0) { virCgroupRemove(*group); virCgroupFree(*group); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - VIR_FREE(grpname); - return ret; + return 0; } =20 =20 @@ -1476,27 +1409,26 @@ virCgroupNewThread(virCgroupPtr domain, bool create, virCgroupPtr *group) { - int ret =3D -1; - char *name =3D NULL; + VIR_AUTOFREE(char *) name =3D NULL; int controllers; =20 switch (nameval) { case VIR_CGROUP_THREAD_VCPU: if (virAsprintf(&name, "vcpu%d", id) < 0) - goto cleanup; + return -1; break; case VIR_CGROUP_THREAD_EMULATOR: if (VIR_STRDUP(name, "emulator") < 0) - goto cleanup; + return -1; break; case VIR_CGROUP_THREAD_IOTHREAD: if (virAsprintf(&name, "iothread%d", id) < 0) - goto cleanup; + return -1; break; case VIR_CGROUP_THREAD_LAST: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected name value %d"), nameval); - goto cleanup; + return -1; } =20 controllers =3D ((1 << VIR_CGROUP_CONTROLLER_CPU) | @@ -1504,18 +1436,15 @@ virCgroupNewThread(virCgroupPtr domain, (1 << VIR_CGROUP_CONTROLLER_CPUSET)); =20 if (virCgroupNew(-1, name, domain, controllers, group) < 0) - goto cleanup; + return -1; =20 if (virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE) < 0) { virCgroupRemove(*group); virCgroupFree(*group); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(name); - return ret; + return 0; } =20 =20 @@ -1576,7 +1505,7 @@ virCgroupNewMachineSystemd(const char *name, int ret =3D -1; int rv; virCgroupPtr init, parent =3D NULL; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; char *offset; =20 VIR_DEBUG("Trying to setup machine '%s' via systemd", name); @@ -1661,7 +1590,6 @@ virCgroupNewMachineSystemd(const char *name, ret =3D 0; cleanup: virCgroupFree(parent); - VIR_FREE(path); return ret; } =20 @@ -1893,9 +1821,11 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, long long *requests_write) { long long stats_val; - char *str1 =3D NULL, *str2 =3D NULL, *p1, *p2; + VIR_AUTOFREE(char *) str1 =3D NULL; + VIR_AUTOFREE(char *) str2 =3D NULL; + char *p1; + char *p2; size_t i; - int ret =3D -1; =20 const char *value_names[] =3D { "Read ", @@ -1918,12 +1848,12 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.io_service_bytes", &str1) < 0) - goto cleanup; + return -1; =20 if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.io_serviced", &str2) < 0) - goto cleanup; + return -1; =20 /* sum up all entries of the same kind, from all devices */ for (i =3D 0; i < ARRAY_CARDINALITY(value_names); i++) { @@ -1937,7 +1867,7 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, _("Cannot parse byte %sstat '%s'"), value_names[i], p1); - goto cleanup; + return -1; } =20 if (stats_val < 0 || @@ -1946,7 +1876,7 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, virReportError(VIR_ERR_OVERFLOW, _("Sum of byte %sstat overflows"), value_names[i]); - goto cleanup; + return -1; } *bytes_ptrs[i] +=3D stats_val; } @@ -1958,7 +1888,7 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, _("Cannot parse %srequest stat '%s'"), value_names[i], p2); - goto cleanup; + return -1; } =20 if (stats_val < 0 || @@ -1967,18 +1897,13 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, virReportError(VIR_ERR_OVERFLOW, _("Sum of %srequest stat overflows"), value_names[i]); - goto cleanup; + return -1; } *requests_ptrs[i] +=3D stats_val; } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(str2); - VIR_FREE(str1); - return ret; + return 0; } =20 =20 @@ -2002,9 +1927,12 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group, long long *requests_read, long long *requests_write) { - char *str1 =3D NULL, *str2 =3D NULL, *str3 =3D NULL, *p1, *p2; + VIR_AUTOFREE(char *) str1 =3D NULL; + VIR_AUTOFREE(char *) str2 =3D NULL; + VIR_AUTOFREE(char *) str3 =3D NULL; + char *p1; + char *p2; size_t i; - int ret =3D -1; =20 const char *value_names[] =3D { "Read ", @@ -2022,28 +1950,28 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr grou= p, if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.io_service_bytes", &str1) < 0) - goto cleanup; + return -1; =20 if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.io_serviced", &str2) < 0) - goto cleanup; + return -1; =20 if (!(str3 =3D virCgroupGetBlockDevString(path))) - goto cleanup; + return -1; =20 if (!(p1 =3D strstr(str1, str3))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find byte stats for block device '%s'"), str3); - goto cleanup; + return -1; } =20 if (!(p2 =3D strstr(str2, str3))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find request stats for block device '%s'"= ), str3); - goto cleanup; + return -1; } =20 for (i =3D 0; i < ARRAY_CARDINALITY(value_names); i++) { @@ -2051,38 +1979,32 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr grou= p, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find byte %sstats for block device '%= s'"), value_names[i], str3); - goto cleanup; + return -1; } =20 if (virStrToLong_ll(p1 + strlen(value_names[i]), &p1, 10, bytes_pt= rs[i]) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse %sstat '%s'"), value_names[i], p1 + strlen(value_names[i])); - goto cleanup; + return -1; } =20 if (!(p2 =3D strstr(p2, value_names[i]))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot find request %sstats for block device= '%s'"), value_names[i], str3); - goto cleanup; + return -1; } =20 if (virStrToLong_ll(p2 + strlen(value_names[i]), &p2, 10, requests= _ptrs[i]) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse %sstat '%s'"), value_names[i], p2 + strlen(value_names[i])); - goto cleanup; + return -1; } } =20 - ret =3D 0; - - cleanup: - VIR_FREE(str3); - VIR_FREE(str2); - VIR_FREE(str1); - return ret; + return 0; } =20 =20 @@ -2138,24 +2060,19 @@ virCgroupSetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int riops) { - char *str =3D NULL; - char *blkstr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; =20 if (!(blkstr =3D virCgroupGetBlockDevString(path))) return -1; =20 if (virAsprintf(&str, "%s%u", blkstr, riops) < 0) - goto error; + return -1; =20 - ret =3D virCgroupSetValueStr(group, + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.read_iops_device", str); - error: - VIR_FREE(blkstr); - VIR_FREE(str); - return ret; } =20 =20 @@ -2172,24 +2089,19 @@ virCgroupSetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int wiops) { - char *str =3D NULL; - char *blkstr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; =20 if (!(blkstr =3D virCgroupGetBlockDevString(path))) return -1; =20 if (virAsprintf(&str, "%s%u", blkstr, wiops) < 0) - goto error; + return -1; =20 - ret =3D virCgroupSetValueStr(group, + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.write_iops_device", str); - error: - VIR_FREE(blkstr); - VIR_FREE(str); - return ret; } =20 =20 @@ -2206,24 +2118,19 @@ virCgroupSetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long rbps) { - char *str =3D NULL; - char *blkstr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; =20 if (!(blkstr =3D virCgroupGetBlockDevString(path))) return -1; =20 if (virAsprintf(&str, "%s%llu", blkstr, rbps) < 0) - goto error; + return -1; =20 - ret =3D virCgroupSetValueStr(group, + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.read_bps_device", str); - error: - VIR_FREE(blkstr); - VIR_FREE(str); - return ret; } =20 /** @@ -2239,24 +2146,19 @@ virCgroupSetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long wbps) { - char *str =3D NULL; - char *blkstr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; =20 if (!(blkstr =3D virCgroupGetBlockDevString(path))) return -1; =20 if (virAsprintf(&str, "%s%llu", blkstr, wbps) < 0) - goto error; + return -1; =20 - ret =3D virCgroupSetValueStr(group, + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.write_bps_device", str); - error: - VIR_FREE(blkstr); - VIR_FREE(str); - return ret; } =20 =20 @@ -2274,24 +2176,19 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int weight) { - char *str =3D NULL; - char *blkstr =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; + VIR_AUTOFREE(char *) blkstr =3D NULL; =20 if (!(blkstr =3D virCgroupGetBlockDevString(path))) return -1; =20 if (virAsprintf(&str, "%s%d", blkstr, weight) < 0) - goto error; + return -1; =20 - ret =3D virCgroupSetValueStr(group, + return virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.weight_device", str); - error: - VIR_FREE(blkstr); - VIR_FREE(str); - return ret; } =20 /** @@ -2307,15 +2204,14 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, const char *path, unsigned int *riops) { - char *str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (virCgroupGetValueForBlkDev(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.read_iops_device", path, &str) < 0) - goto error; + return -1; =20 if (!str) { *riops =3D 0; @@ -2323,13 +2219,10 @@ virCgroupGetBlkioDeviceReadIops(virCgroupPtr group, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); - goto error; + return -1; } =20 - ret =3D 0; - error: - VIR_FREE(str); - return ret; + return 0; } =20 /** @@ -2345,15 +2238,14 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, const char *path, unsigned int *wiops) { - char *str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (virCgroupGetValueForBlkDev(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.write_iops_device", path, &str) < 0) - goto error; + return -1; =20 if (!str) { *wiops =3D 0; @@ -2361,13 +2253,10 @@ virCgroupGetBlkioDeviceWriteIops(virCgroupPtr group, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); - goto error; + return -1; } =20 - ret =3D 0; - error: - VIR_FREE(str); - return ret; + return 0; } =20 /** @@ -2383,15 +2272,14 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, const char *path, unsigned long long *rbps) { - char *str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (virCgroupGetValueForBlkDev(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.read_bps_device", path, &str) < 0) - goto error; + return -1; =20 if (!str) { *rbps =3D 0; @@ -2399,13 +2287,10 @@ virCgroupGetBlkioDeviceReadBps(virCgroupPtr group, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); - goto error; + return -1; } =20 - ret =3D 0; - error: - VIR_FREE(str); - return ret; + return 0; } =20 /** @@ -2421,15 +2306,14 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, const char *path, unsigned long long *wbps) { - char *str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (virCgroupGetValueForBlkDev(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.throttle.write_bps_device", path, &str) < 0) - goto error; + return -1; =20 if (!str) { *wbps =3D 0; @@ -2437,13 +2321,10 @@ virCgroupGetBlkioDeviceWriteBps(virCgroupPtr group, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); - goto error; + return -1; } =20 - ret =3D 0; - error: - VIR_FREE(str); - return ret; + return 0; } =20 /** @@ -2459,15 +2340,14 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group, const char *path, unsigned int *weight) { - char *str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) str =3D NULL; =20 if (virCgroupGetValueForBlkDev(group, VIR_CGROUP_CONTROLLER_BLKIO, "blkio.weight_device", path, &str) < 0) - goto error; + return -1; =20 if (!str) { *weight =3D 0; @@ -2475,13 +2355,10 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse '%s' as an integer"), str); - goto error; + return -1; } =20 - ret =3D 0; - error: - VIR_FREE(str); - return ret; + return 0; } =20 =20 @@ -2940,36 +2817,29 @@ int virCgroupAllowDevice(virCgroupPtr group, char type, int major, int minor, int perms) { - int ret =3D -1; - char *devstr =3D NULL; - char *majorstr =3D NULL; - char *minorstr =3D NULL; + VIR_AUTOFREE(char *) devstr =3D NULL; + VIR_AUTOFREE(char *) majorstr =3D NULL; + VIR_AUTOFREE(char *) minorstr =3D NULL; =20 if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) || (major >=3D 0 && virAsprintf(&majorstr, "%i", major) < 0)) - goto cleanup; + return -1; =20 if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) || (minor >=3D 0 && virAsprintf(&minorstr, "%i", minor) < 0)) - goto cleanup; + return -1; =20 if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, virCgroupGetDevicePermsString(perms)) < 0) - goto cleanup; + return -1; =20 if (virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_DEVICES, "devices.allow", devstr) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - VIR_FREE(devstr); - VIR_FREE(majorstr); - VIR_FREE(minorstr); - return ret; + return 0; } =20 =20 @@ -3031,36 +2901,29 @@ int virCgroupDenyDevice(virCgroupPtr group, char type, int major, int minor, int perms) { - int ret =3D -1; - char *devstr =3D NULL; - char *majorstr =3D NULL; - char *minorstr =3D NULL; + VIR_AUTOFREE(char *) devstr =3D NULL; + VIR_AUTOFREE(char *) majorstr =3D NULL; + VIR_AUTOFREE(char *) minorstr =3D NULL; =20 if ((major < 0 && VIR_STRDUP(majorstr, "*") < 0) || (major >=3D 0 && virAsprintf(&majorstr, "%i", major) < 0)) - goto cleanup; + return -1; =20 if ((minor < 0 && VIR_STRDUP(minorstr, "*") < 0) || (minor >=3D 0 && virAsprintf(&minorstr, "%i", minor) < 0)) - goto cleanup; + return -1; =20 if (virAsprintf(&devstr, "%c %s:%s %s", type, majorstr, minorstr, virCgroupGetDevicePermsString(perms)) < 0) - goto cleanup; + return -1; =20 if (virCgroupSetValueStr(group, VIR_CGROUP_CONTROLLER_DEVICES, "devices.deny", devstr) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - VIR_FREE(devstr); - VIR_FREE(majorstr); - VIR_FREE(minorstr); - return ret; + return 0; } =20 =20 @@ -3130,10 +2993,10 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group, { int ret =3D -1; ssize_t i =3D -1; - char *buf =3D NULL; virCgroupPtr group_vcpu =3D NULL; =20 while ((i =3D virBitmapNextSetBit(guestvcpus, i)) >=3D 0) { + VIR_AUTOFREE(char *) buf =3D NULL; char *pos; unsigned long long tmp; ssize_t j; @@ -3158,13 +3021,11 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group, } =20 virCgroupFree(group_vcpu); - VIR_FREE(buf); } =20 ret =3D 0; cleanup: virCgroupFree(group_vcpu); - VIR_FREE(buf); return ret; } =20 @@ -3201,8 +3062,8 @@ virCgroupGetPercpuStats(virCgroupPtr group, size_t i; int need_cpus, total_cpus; char *pos; - char *buf =3D NULL; - unsigned long long *sum_cpu_time =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOFREE(unsigned long long *) sum_cpu_time =3D NULL; virTypedParameterPtr ent; int param_idx; unsigned long long cpu_time; @@ -3288,8 +3149,6 @@ virCgroupGetPercpuStats(virCgroupPtr group, =20 cleanup: virBitmapFree(cpumap); - VIR_FREE(sum_cpu_time); - VIR_FREE(buf); return ret; } =20 @@ -3460,7 +3319,7 @@ virCgroupRemoveRecursively(char *grppath) /* This is best-effort cleanup: we want to log failures with just * VIR_ERROR instead of normal virReportError */ while ((direrr =3D virDirRead(grpdir, &ent, NULL)) > 0) { - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (ent->d_type !=3D DT_DIR) continue; =20 @@ -3469,7 +3328,6 @@ virCgroupRemoveRecursively(char *grppath) break; } rc =3D virCgroupRemoveRecursively(path); - VIR_FREE(path); if (rc !=3D 0) break; } @@ -3507,10 +3365,11 @@ virCgroupRemove(virCgroupPtr group) { int rc =3D 0; size_t i; - char *grppath =3D NULL; =20 VIR_DEBUG("Removing cgroup %s", group->path); for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_AUTOFREE(char *) grppath =3D NULL; + /* Skip over controllers not mounted */ if (!group->controllers[i].mountPoint) continue; @@ -3532,7 +3391,6 @@ virCgroupRemove(virCgroupPtr group) =20 VIR_DEBUG("Removing cgroup %s and all child cgroups", grppath); rc =3D virCgroupRemoveRecursively(grppath); - VIR_FREE(grppath); } VIR_DEBUG("Done removing cgroup %s", group->path); =20 @@ -3548,7 +3406,7 @@ virCgroupKillInternal(virCgroupPtr group, int signum,= virHashTablePtr pids) { int ret =3D -1; bool killedAny =3D false; - char *keypath =3D NULL; + VIR_AUTOFREE(char *) keypath =3D NULL; bool done =3D false; FILE *fp =3D NULL; VIR_DEBUG("group=3D%p path=3D%s signum=3D%d pids=3D%p", @@ -3612,7 +3470,6 @@ virCgroupKillInternal(virCgroupPtr group, int signum,= virHashTablePtr pids) ret =3D killedAny ? 1 : 0; =20 cleanup: - VIR_FREE(keypath); VIR_FORCE_FCLOSE(fp); =20 return ret; @@ -3677,7 +3534,7 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, int ret =3D -1; int rc; bool killedAny =3D false; - char *keypath =3D NULL; + VIR_AUTOFREE(char *) keypath =3D NULL; DIR *dp =3D NULL; virCgroupPtr subgroup =3D NULL; struct dirent *ent; @@ -3731,7 +3588,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, =20 cleanup: virCgroupFree(subgroup); - VIR_FREE(keypath); VIR_DIR_CLOSE(dp); return ret; } @@ -3845,9 +3701,8 @@ int virCgroupGetCpuacctStat(virCgroupPtr group, unsigned long long *user, unsigned long long *sys) { - char *str; + VIR_AUTOFREE(char *) str =3D NULL; char *p; - int ret =3D -1; static double scale =3D -1.0; =20 if (virCgroupGetValueStr(group, VIR_CGROUP_CONTROLLER_CPUACCT, @@ -3859,14 +3714,14 @@ virCgroupGetCpuacctStat(virCgroupPtr group, unsigne= d long long *user, virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse user stat '%s'"), p); - goto cleanup; + return -1; } if (!(p =3D STRSKIP(p, "\nsystem ")) || virStrToLong_ull(p, NULL, 10, sys) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Cannot parse sys stat '%s'"), p); - goto cleanup; + return -1; } /* times reported are in system ticks (generally 100 Hz), but that * rate can theoretically vary between machines. Scale things @@ -3876,17 +3731,14 @@ virCgroupGetCpuacctStat(virCgroupPtr group, unsigne= d long long *user, if (ticks_per_sec =3D=3D -1) { virReportSystemError(errno, "%s", _("Cannot determine system clock HZ")); - goto cleanup; + return -1; } scale =3D 1000000000.0 / ticks_per_sec; } *user *=3D scale; *sys *=3D scale; =20 - ret =3D 0; - cleanup: - VIR_FREE(str); - return ret; + return 0; } =20 =20 @@ -3912,10 +3764,9 @@ int virCgroupBindMount(virCgroupPtr group, const char *oldroot, const char *mountopts) { - int ret =3D -1; size_t i; - char *opts =3D NULL; - char *root =3D NULL; + VIR_AUTOFREE(char *) opts =3D NULL; + VIR_AUTOFREE(char *) root =3D NULL; =20 if (!(root =3D virCgroupIdentifyRoot(group))) return -1; @@ -3926,18 +3777,18 @@ virCgroupBindMount(virCgroupPtr group, const char *= oldroot, virReportSystemError(errno, _("Unable to create directory %s"), root); - goto cleanup; + return -1; } =20 if (virAsprintf(&opts, "mode=3D755,size=3D65536%s", mountopts) < 0) - goto cleanup; + return -1; =20 if (mount("tmpfs", root, "tmpfs", MS_NOSUID|MS_NODEV|MS_NOEXEC, opts) = < 0) { virReportSystemError(errno, _("Failed to mount %s on %s type %s"), "tmpfs", root, "tmpfs"); - goto cleanup; + return -1; } =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { @@ -3945,11 +3796,11 @@ virCgroupBindMount(virCgroupPtr group, const char *= oldroot, continue; =20 if (!virFileExists(group->controllers[i].mountPoint)) { - char *src; + VIR_AUTOFREE(char *) src =3D NULL; if (virAsprintf(&src, "%s%s", oldroot, group->controllers[i].mountPoint) < 0) - goto cleanup; + return -1; =20 VIR_DEBUG("Create mount point '%s'", group->controllers[i].mountPoint); @@ -3957,8 +3808,7 @@ virCgroupBindMount(virCgroupPtr group, const char *ol= droot, virReportSystemError(errno, _("Unable to create directory %s"), group->controllers[i].mountPoint); - VIR_FREE(src); - goto cleanup; + return -1; } =20 if (mount(src, group->controllers[i].mountPoint, "none", MS_BI= ND, @@ -3966,11 +3816,8 @@ virCgroupBindMount(virCgroupPtr group, const char *o= ldroot, virReportSystemError(errno, _("Failed to bind cgroup '%s' on '%s'= "), src, group->controllers[i].mountPoint= ); - VIR_FREE(src); - goto cleanup; + return -1; } - - VIR_FREE(src); } =20 if (group->controllers[i].linkPoint) { @@ -3983,16 +3830,12 @@ virCgroupBindMount(virCgroupPtr group, const char *= oldroot, _("Unable to symlink directory %s to = %s"), group->controllers[i].mountPoint, group->controllers[i].linkPoint); - goto cleanup; + return -1; } } } - ret =3D 0; =20 - cleanup: - VIR_FREE(root); - VIR_FREE(opts); - return ret; + return 0; } =20 =20 @@ -4003,11 +3846,11 @@ int virCgroupSetOwner(virCgroupPtr cgroup, { int ret =3D -1; size_t i; - char *base =3D NULL, *entry =3D NULL; DIR *dh =3D NULL; int direrr; =20 for (i =3D 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) { + VIR_AUTOFREE(char *) base =3D NULL; struct dirent *de; =20 if (!((1 << i) & controllers)) @@ -4024,6 +3867,8 @@ int virCgroupSetOwner(virCgroupPtr cgroup, goto cleanup; =20 while ((direrr =3D virDirRead(dh, &de, base)) > 0) { + VIR_AUTOFREE(char *) entry =3D NULL; + if (virAsprintf(&entry, "%s/%s", base, de->d_name) < 0) goto cleanup; =20 @@ -4033,8 +3878,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup, entry, uid, gid); goto cleanup; } - - VIR_FREE(entry); } if (direrr < 0) goto cleanup; @@ -4046,7 +3889,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup, goto cleanup; } =20 - VIR_FREE(base); VIR_DIR_CLOSE(dh); } =20 @@ -4054,8 +3896,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup, =20 cleanup: VIR_DIR_CLOSE(dh); - VIR_FREE(entry); - VIR_FREE(base); return ret; } =20 @@ -4070,8 +3910,7 @@ int virCgroupSetOwner(virCgroupPtr cgroup, bool virCgroupSupportsCpuBW(virCgroupPtr cgroup) { - char *path =3D NULL; - bool ret =3D false; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (!cgroup) return false; @@ -4079,21 +3918,17 @@ virCgroupSupportsCpuBW(virCgroupPtr cgroup) if (virCgroupPathOfController(cgroup, VIR_CGROUP_CONTROLLER_CPU, "cpu.cfs_period_us", &path) < 0) { virResetLastError(); - goto cleanup; + return false; } =20 - ret =3D virFileExists(path); - - cleanup: - VIR_FREE(path); - return ret; + return virFileExists(path); } =20 int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller) { int ret =3D -1; - char *content =3D NULL; + VIR_AUTOFREE(char *) content =3D NULL; =20 if (!cgroup) return -1; @@ -4103,7 +3938,6 @@ virCgroupHasEmptyTasks(virCgroupPtr cgroup, int contr= oller) if (ret =3D=3D 0 && content[0] =3D=3D '\0') ret =3D 1; =20 - VIR_FREE(content); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174961210305.0741920029294; Sat, 21 Jul 2018 05:09:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BC5287649; Sat, 21 Jul 2018 12:09:13 +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 CDE2E308BDB7; Sat, 21 Jul 2018 12:09:12 +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 8370B1841C4B; Sat, 21 Jul 2018 12:09:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC7xea016277 for ; Sat, 21 Jul 2018 08:07:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0DF39308332E; Sat, 21 Jul 2018 12:07:59 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 069E43001A45 for ; Sat, 21 Jul 2018 12:07:59 +0000 (UTC) Received: from mail-pl0-f44.google.com (mail-pl0-f44.google.com [209.85.160.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C5A4D30E686B for ; Sat, 21 Jul 2018 12:07:47 +0000 (UTC) Received: by mail-pl0-f44.google.com with SMTP id t17-v6so3749141ply.13 for ; Sat, 21 Jul 2018 05:07:47 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.45 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=heBBF9N4Me3i0Klna29onmddmTnSFtunhXPDvaj1XY8=; b=K9AnJHXMgkGHLJHaoeR6Sd8Dh8Fj2KSRIgno1dt5JyUSRAoWh1QVuO9sk01IJyD9Hf CJ4VrRzB3zZ16/bALHcdeFzzVfLDZhSEXxEFuGd5LECWMBneMa86z8mRSufJef6qYNak 4A8w74lfxJ11pld4i/ulUSNolbDZBHTx4zAkKKdk2UAYurTwS2tocEx8lmwBJogL4cpw CkilHsHfReojEV/tQRMErx3XVi64r2pZ3r0tNmrCDXfiVlUSFiwt2/rjwJGJk32w8HHW BiEk2gaRqWKYGS32io4u1ZU2c8r56pKUA+Vu+B0GWcJAnEbzEW3cRQPs9zHRPgyKkuTp mpPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=heBBF9N4Me3i0Klna29onmddmTnSFtunhXPDvaj1XY8=; b=N4HF3Z8ITuKHE+WJbnfIcnlrtXyxZUIP5HG0R2AjkSESq4HskNRX7gVHDyBt7Wobq/ I5i3OJGKBcdh5YApSGBWWC/IcsNY/J6FAG3ZY4+p00vCGqGpB5EJAaL96lIrMllOPWRV eamSZ621rE6hzbrtat74FGg/PjSTzudhlHNDZExwIX/oL3hY5lEt1KR+vUYZtrR+/psc Dn7XPlx3k4ndvl0mIrD/YZLs9Wqbb3twIO93N5ZaTgMD5ktoJIOwBTrwA4Auo2mwgPBD 4FFpBFw31CjPIc9d9NSjcvRYWVTFpzQ2xK8te6KEUZWJeQK6KYKNW28LvRBzdLeIeAkv ohuA== X-Gm-Message-State: AOUpUlFNFhYRE3v11nTCjspsX4J0EDIugkmikazVSUFWRVbx3v6je7B/ a5BP6NpUM8BF44jZoqnOgGL9lXwi X-Google-Smtp-Source: AAOMgpe4ROYWueQclRdAWvDBuoIRkAJ4rV+fhYQxnj4m2v1O9rAoe/KNGN9OZtUDNRoHB1jWILqKIA== X-Received: by 2002:a17:902:22e:: with SMTP id 43-v6mr5782689plc.82.1532174867080; Sat, 21 Jul 2018 05:07:47 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:42 +0530 Message-Id: <1532174832-21644-11-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 21 Jul 2018 12:07:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 21 Jul 2018 12:07:47 +0000 (UTC) for IP:'209.85.160.44' DOMAIN:'mail-pl0-f44.google.com' HELO:'mail-pl0-f44.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.160.44 mail-pl0-f44.google.com 209.85.160.44 mail-pl0-f44.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 10/40] util: cgroup: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:09:20 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/vircgroup.c | 155 +++++++++++++++++------------------------------= ---- 1 file changed, 52 insertions(+), 103 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 4bb4408..cdb493e 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -836,25 +836,21 @@ virCgroupGetValueForBlkDev(virCgroupPtr group, { VIR_AUTOFREE(char *) prefix =3D NULL; VIR_AUTOFREE(char *) str =3D NULL; - char **lines =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virString) lines =3D NULL; =20 if (virCgroupGetValueStr(group, controller, key, &str) < 0) - goto error; + return -1; =20 if (!(prefix =3D virCgroupGetBlockDevString(path))) - goto error; + return -1; =20 if (!(lines =3D virStringSplit(str, "\n", -1))) - goto error; + return -1; =20 if (VIR_STRDUP(*value, virStringListGetFirstWithPrefix(lines, prefix))= < 0) - goto error; + return -1; =20 - ret =3D 0; - error: - virStringListFree(lines); - return ret; + return 0; } =20 =20 @@ -1217,12 +1213,11 @@ virCgroupAddTaskController(virCgroupPtr group, pid_= t pid, int controller) static int virCgroupSetPartitionSuffix(const char *path, char **res) { - char **tokens; + VIR_AUTOPTR(virString) tokens =3D NULL; size_t i; - int ret =3D -1; =20 if (!(tokens =3D virStringSplit(path, "/", 0))) - return ret; + return -1; =20 for (i =3D 0; tokens[i] !=3D NULL; i++) { /* Whitelist the 3 top level fixed dirs @@ -1241,22 +1236,18 @@ virCgroupSetPartitionSuffix(const char *path, char = **res) !strchr(tokens[i], '.')) { if (VIR_REALLOC_N(tokens[i], strlen(tokens[i]) + strlen(".partition") + 1= ) < 0) - goto cleanup; + return -1; strcat(tokens[i], ".partition"); } =20 if (virCgroupPartitionEscape(&(tokens[i])) < 0) - goto cleanup; + return -1; } =20 if (!(*res =3D virStringListJoin((const char **)tokens, "/"))) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virStringListFree(tokens); - return ret; + return 0; } =20 =20 @@ -1280,7 +1271,7 @@ virCgroupNewPartition(const char *path, int ret =3D -1; VIR_AUTOFREE(char *) parentPath =3D NULL; VIR_AUTOFREE(char *) newPath =3D NULL; - virCgroupPtr parent =3D NULL; + VIR_AUTOPTR(virCgroup) parent =3D NULL; VIR_DEBUG("path=3D%s create=3D%d controllers=3D%x", path, create, controllers); =20 @@ -1319,7 +1310,6 @@ virCgroupNewPartition(const char *path, cleanup: if (ret !=3D 0) virCgroupFree(*group); - virCgroupFree(parent); return ret; } =20 @@ -1502,9 +1492,9 @@ virCgroupNewMachineSystemd(const char *name, int controllers, virCgroupPtr *group) { - int ret =3D -1; int rv; - virCgroupPtr init, parent =3D NULL; + VIR_AUTOPTR(virCgroup) init =3D NULL; + VIR_AUTOPTR(virCgroup) parent =3D NULL; VIR_AUTOFREE(char *) path =3D NULL; char *offset; =20 @@ -1531,12 +1521,10 @@ virCgroupNewMachineSystemd(const char *name, =20 path =3D init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement; init->controllers[VIR_CGROUP_CONTROLLER_SYSTEMD].placement =3D NULL; - virCgroupFree(init); =20 if (!path || STREQ(path, "/") || path[0] !=3D '/') { VIR_DEBUG("Systemd didn't setup its controller"); - ret =3D -2; - goto cleanup; + return -2; } =20 offset =3D path; @@ -1546,7 +1534,7 @@ virCgroupNewMachineSystemd(const char *name, NULL, controllers, &parent) < 0) - goto cleanup; + return -1; =20 =20 for (;;) { @@ -1560,11 +1548,11 @@ virCgroupNewMachineSystemd(const char *name, parent, controllers, &tmp) < 0) - goto cleanup; + return -1; =20 if (virCgroupMakeGroup(parent, tmp, true, VIR_CGROUP_NONE) < 0) { virCgroupFree(tmp); - goto cleanup; + return -1; } if (t) { *t =3D '/'; @@ -1587,10 +1575,7 @@ virCgroupNewMachineSystemd(const char *name, } } =20 - ret =3D 0; - cleanup: - virCgroupFree(parent); - return ret; + return 0; } =20 =20 @@ -1611,8 +1596,7 @@ virCgroupNewMachineManual(const char *name, int controllers, virCgroupPtr *group) { - virCgroupPtr parent =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virCgroup) parent =3D NULL; =20 VIR_DEBUG("Fallback to non-systemd setup"); if (virCgroupNewPartition(partition, @@ -1620,9 +1604,9 @@ virCgroupNewMachineManual(const char *name, controllers, &parent) < 0) { if (virCgroupNewIgnoreError()) - goto done; + return 0; =20 - goto cleanup; + return -1; } =20 if (virCgroupNewDomainPartition(parent, @@ -1630,7 +1614,7 @@ virCgroupNewMachineManual(const char *name, name, true, group) < 0) - goto cleanup; + return -1; =20 if (virCgroupAddTask(*group, pidleader) < 0) { virErrorPtr saved =3D virSaveLastError(); @@ -1642,12 +1626,7 @@ virCgroupNewMachineManual(const char *name, } } =20 - done: - ret =3D 0; - - cleanup: - virCgroupFree(parent); - return ret; + return 0; } =20 =20 @@ -2376,7 +2355,7 @@ static virOnceControl virCgroupMemoryOnce =3D VIR_ONC= E_CONTROL_INITIALIZER; static void virCgroupMemoryOnceInit(void) { - virCgroupPtr group; + VIR_AUTOPTR(virCgroup) group =3D NULL; unsigned long long int mem_unlimited =3D 0ULL; =20 if (virCgroupNew(-1, "/", NULL, -1, &group) < 0) @@ -2390,7 +2369,6 @@ virCgroupMemoryOnceInit(void) "memory.limit_in_bytes", &mem_unlimited)); cleanup: - virCgroupFree(group); virCgroupMemoryUnlimitedKB =3D mem_unlimited >> 10; } =20 @@ -2991,22 +2969,21 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group, size_t nsum, virBitmapPtr cpumap) { - int ret =3D -1; ssize_t i =3D -1; - virCgroupPtr group_vcpu =3D NULL; =20 while ((i =3D virBitmapNextSetBit(guestvcpus, i)) >=3D 0) { VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOPTR(virCgroup) group_vcpu =3D NULL; char *pos; unsigned long long tmp; ssize_t j; =20 if (virCgroupNewThread(group, VIR_CGROUP_THREAD_VCPU, i, false, &group_vcpu) < 0) - goto cleanup; + return -1; =20 if (virCgroupGetCpuacctPercpuUsage(group_vcpu, &buf) < 0) - goto cleanup; + return -1; =20 pos =3D buf; for (j =3D virBitmapNextSetBit(cpumap, -1); @@ -3015,18 +2992,13 @@ virCgroupGetPercpuVcpuSum(virCgroupPtr group, if (virStrToLong_ull(pos, &pos, 10, &tmp) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cpuacct parse error")); - goto cleanup; + return -1; } sum_cpu_time[j] +=3D tmp; } - - virCgroupFree(group_vcpu); } =20 - ret =3D 0; - cleanup: - virCgroupFree(group_vcpu); - return ret; + return 0; } =20 =20 @@ -3058,7 +3030,6 @@ virCgroupGetPercpuStats(virCgroupPtr group, unsigned int ncpus, virBitmapPtr guestvcpus) { - int ret =3D -1; size_t i; int need_cpus, total_cpus; char *pos; @@ -3067,7 +3038,7 @@ virCgroupGetPercpuStats(virCgroupPtr group, virTypedParameterPtr ent; int param_idx; unsigned long long cpu_time; - virBitmapPtr cpumap =3D NULL; + VIR_AUTOPTR(virBitmap) cpumap =3D NULL; =20 /* return the number of supported params */ if (nparams =3D=3D 0 && ncpus !=3D 0) { @@ -3084,21 +3055,19 @@ virCgroupGetPercpuStats(virCgroupPtr group, total_cpus =3D virBitmapSize(cpumap); =20 /* return total number of cpus */ - if (ncpus =3D=3D 0) { - ret =3D total_cpus; - goto cleanup; - } + if (ncpus =3D=3D 0) + return total_cpus; =20 if (start_cpu >=3D total_cpus) { virReportError(VIR_ERR_INVALID_ARG, _("start_cpu %d larger than maximum of %d"), start_cpu, total_cpus - 1); - goto cleanup; + return -1; } =20 /* we get percpu cputime accounting info. */ if (virCgroupGetCpuacctPercpuUsage(group, &buf)) - goto cleanup; + return -1; pos =3D buf; =20 /* return percpu cputime in index 0 */ @@ -3113,14 +3082,14 @@ virCgroupGetPercpuStats(virCgroupPtr group, } else if (virStrToLong_ull(pos, &pos, 10, &cpu_time) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cpuacct parse error")); - goto cleanup; + return -1; } if (i < start_cpu) continue; ent =3D ¶ms[(i - start_cpu) * nparams + param_idx]; if (virTypedParameterAssign(ent, VIR_DOMAIN_CPU_STATS_CPUTIME, VIR_TYPED_PARAM_ULLONG, cpu_time) < 0) - goto cleanup; + return -1; } =20 /* return percpu vcputime in index 1 */ @@ -3128,10 +3097,10 @@ virCgroupGetPercpuStats(virCgroupPtr group, =20 if (guestvcpus && param_idx < nparams) { if (VIR_ALLOC_N(sum_cpu_time, need_cpus) < 0) - goto cleanup; + return -1; if (virCgroupGetPercpuVcpuSum(group, guestvcpus, sum_cpu_time, need_cpus, cpumap) < 0) - goto cleanup; + return -1; =20 for (i =3D start_cpu; i < need_cpus; i++) { if (virTypedParameterAssign(¶ms[(i - start_cpu) * nparams + @@ -3139,17 +3108,13 @@ virCgroupGetPercpuStats(virCgroupPtr group, VIR_DOMAIN_CPU_STATS_VCPUTIME, VIR_TYPED_PARAM_ULLONG, sum_cpu_time[i]) < 0) - goto cleanup; + return -1; } =20 param_idx++; } =20 - ret =3D param_idx; - - cleanup: - virBitmapFree(cpumap); - return ret; + return param_idx; } =20 =20 @@ -3505,23 +3470,18 @@ int virCgroupKill(virCgroupPtr group, int signum) { VIR_DEBUG("group=3D%p path=3D%s signum=3D%d", group, group->path, sign= um); - int ret; /* The 'tasks' file in cgroups can contain duplicated * pids, so we use a hash to track which we've already * killed. */ - virHashTablePtr pids =3D virHashCreateFull(100, + VIR_AUTOPTR(virHashTable) pids =3D virHashCreateFull(100, NULL, virCgroupPidCode, virCgroupPidEqual, virCgroupPidCopy, NULL); =20 - ret =3D virCgroupKillInternal(group, signum, pids); - - virHashFree(pids); - - return ret; + return virCgroupKillInternal(group, signum, pids); } =20 =20 @@ -3536,7 +3496,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, bool killedAny =3D false; VIR_AUTOFREE(char *) keypath =3D NULL; DIR *dp =3D NULL; - virCgroupPtr subgroup =3D NULL; struct dirent *ent; int direrr; VIR_DEBUG("group=3D%p path=3D%s signum=3D%d pids=3D%p", @@ -3561,6 +3520,8 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, } =20 while ((direrr =3D virDirRead(dp, &ent, keypath)) > 0) { + VIR_AUTOPTR(virCgroup) subgroup =3D NULL; + if (ent->d_type !=3D DT_DIR) continue; =20 @@ -3577,8 +3538,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, =20 if (dormdir) virCgroupRemove(subgroup); - - virCgroupFree(subgroup); } if (direrr < 0) goto cleanup; @@ -3587,7 +3546,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, ret =3D killedAny ? 1 : 0; =20 cleanup: - virCgroupFree(subgroup); VIR_DIR_CLOSE(dp); return ret; } @@ -3596,20 +3554,15 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, int virCgroupKillRecursive(virCgroupPtr group, int signum) { - int ret; VIR_DEBUG("group=3D%p path=3D%s signum=3D%d", group, group->path, sign= um); - virHashTablePtr pids =3D virHashCreateFull(100, + VIR_AUTOPTR(virHashTable) pids =3D virHashCreateFull(100, NULL, virCgroupPidCode, virCgroupPidEqual, virCgroupPidCopy, NULL); =20 - ret =3D virCgroupKillRecursiveInternal(group, signum, pids, false); - - virHashFree(pids); - - return ret; + return virCgroupKillRecursiveInternal(group, signum, pids, false); } =20 =20 @@ -3944,15 +3897,12 @@ virCgroupHasEmptyTasks(virCgroupPtr cgroup, int con= troller) bool virCgroupControllerAvailable(int controller) { - virCgroupPtr cgroup; - bool ret =3D false; + VIR_AUTOPTR(virCgroup) cgroup =3D NULL; =20 if (virCgroupNewSelf(&cgroup) < 0) - return ret; + return false; =20 - ret =3D virCgroupHasController(cgroup, controller); - virCgroupFree(cgroup); - return ret; + return virCgroupHasController(cgroup, controller); } =20 #else /* !VIR_CGROUP_SUPPORTED */ @@ -4740,7 +4690,7 @@ virCgroupDelThread(virCgroupPtr cgroup, virCgroupThreadName nameval, int idx) { - virCgroupPtr new_cgroup =3D NULL; + VIR_AUTOPTR(virCgroup) new_cgroup =3D NULL; =20 if (cgroup) { if (virCgroupNewThread(cgroup, nameval, idx, false, &new_cgroup) <= 0) @@ -4748,7 +4698,6 @@ virCgroupDelThread(virCgroupPtr cgroup, =20 /* Remove the offlined cgroup */ virCgroupRemove(new_cgroup); - virCgroupFree(new_cgroup); } =20 return 0; --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174982478652.3419393960912; Sat, 21 Jul 2018 05:09:42 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 286A08762E; Sat, 21 Jul 2018 12:09:36 +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 E375717AF9; Sat, 21 Jul 2018 12:09:34 +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 6CD391841C4B; Sat, 21 Jul 2018 12:09:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC83Id016302 for ; Sat, 21 Jul 2018 08:08:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 839FD600C7; Sat, 21 Jul 2018 12:08:03 +0000 (UTC) Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7B9DD600C6 for ; Sat, 21 Jul 2018 12:08:00 +0000 (UTC) Received: from mail-pl0-f54.google.com (mail-pl0-f54.google.com [209.85.160.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 32C6881DE6 for ; Sat, 21 Jul 2018 12:07:50 +0000 (UTC) Received: by mail-pl0-f54.google.com with SMTP id t17-v6so3749161ply.13 for ; Sat, 21 Jul 2018 05:07:50 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=kWrioItjtK9sZKakHI5TunDd7fH4bBuTUolJ/tpMv2A=; b=OyB9hoLZGrKg7xtFRFb3OO+wdJfuiZhL45O2Kb2oS+aEMLp9eAu3hCPB2WzyxCyhCG O7Fug9w9PGpzNCwRp9IjIGSBuAouioXw5pLLZioGxQp5JXgx02l2AmtMrEpVqkF1oWex 1KUQu5ne+Wpxm2CMMq+bfbUyPV8dB+y1FFHUoh6+1pmq8CPXTTd1yTdxLsv40S1vqZbt 9Pfce7daoPDgdRvysiFeXSBGFTdJ99COEtNQ8RZyMJVALGFIP0u1ez7B/UrYXIzIl0rA qFYV7xQ2RVArtEuZaS4eFFRQjj1v+WPCGzzxmYxj0VbUFFLruRmGE2kvcEwAmpkpqtya J+rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=kWrioItjtK9sZKakHI5TunDd7fH4bBuTUolJ/tpMv2A=; b=bm8zlELxNMukTkxhs7WJRzAp3vK22pSN3g9WyKQQvPOWFzBOrAwyL7PxwGS0OgC0m3 jCcdBM19Bh8yBnj4y1/Lq3PeKQEs7l4ossKDV4/UB4fuBZTmghQckf0zxD5Ofl3mtELS p8Gsj75WXpLLWuqL63LDt/jQLLA6jsdDC5Z+BuzkNQSz4RQg5LO3bY24fS4t5GLG3NT/ fSwU1TmQSjWEYYns8+aBNct0plIdt0g/lkvZ2T+y0qpnx2x+xNOPHeckWa48Mb8yHfzS o8S7Bpnbx5rroPha+fIYIIvaDxk3RJwjzh91irZfOXfO5NqIr50nlWdjUdBjZ8RtS0GM ePxQ== X-Gm-Message-State: AOUpUlHhcFQkS01q2hgrKMsELWdbBGeXnh39H2+7nogqeTQRIgbq2OAJ YHUtng5Hv1mgicmNkkS656ayJXmH X-Google-Smtp-Source: AAOMgpewXn3G2BF3Nt8CD3vGBB8MNr9bapo4jqj41uyIq7IhN5QSo2q5tAuVuv1BbfhQvT5iTu3XXw== X-Received: by 2002:a17:902:142:: with SMTP id 60-v6mr3568994plb.330.1532174869437; Sat, 21 Jul 2018 05:07:49 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:43 +0530 Message-Id: <1532174832-21644-12-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 21 Jul 2018 12:07:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 21 Jul 2018 12:07:50 +0000 (UTC) for IP:'209.85.160.54' DOMAIN:'mail-pl0-f54.google.com' HELO:'mail-pl0-f54.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.160.54 mail-pl0-f54.google.com 209.85.160.54 mail-pl0-f54.google.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 11/40] util: mdev: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:09:41 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When variables of type virMediatedDevicePtr and virMediatedDeviceTypePtr are declared using VIR_AUTOPTR, the functions virMediatedDeviceFree and virMediatedDeviceTypeFree, respectively, will be run automatically on them when they go out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virmdev.c | 1 - src/util/virmdev.h | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 6c51388..d7bcb1d 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -21,7 +21,6 @@ #include "dirname.h" #include "virmdev.h" #include "virlog.h" -#include "viralloc.h" #include "virerror.h" #include "virfile.h" #include "virstring.h" diff --git a/src/util/virmdev.h b/src/util/virmdev.h index cfda2ca..7c93c4d 100644 --- a/src/util/virmdev.h +++ b/src/util/virmdev.h @@ -22,6 +22,7 @@ # include "internal.h" # include "virobject.h" # include "virutil.h" +# include "viralloc.h" =20 typedef enum { VIR_MDEV_MODEL_TYPE_VFIO_PCI =3D 0, @@ -135,4 +136,7 @@ int virMediatedDeviceTypeReadAttrs(const char *sysfspath, virMediatedDeviceTypePtr *type); =20 +VIR_DEFINE_AUTOPTR_FUNC(virMediatedDevice, virMediatedDeviceFree) +VIR_DEFINE_AUTOPTR_FUNC(virMediatedDeviceType, virMediatedDeviceTypeFree) + #endif /* __VIR_MDEV_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174934948464.79827546648835; Sat, 21 Jul 2018 05:08:54 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4EDB180F8E; Sat, 21 Jul 2018 12:08: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 18C89308BDAE; Sat, 21 Jul 2018 12:08: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 BB28C4EE13; Sat, 21 Jul 2018 12:08:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC839x016307 for ; Sat, 21 Jul 2018 08:08:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id B1F31600C4; Sat, 21 Jul 2018 12:08:03 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A2D01600C6 for ; Sat, 21 Jul 2018 12:08:03 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8B82485540 for ; Sat, 21 Jul 2018 12:07:52 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id r1-v6so8965513pgp.11 for ; Sat, 21 Jul 2018 05:07:52 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=oRQw1FMOdExMekWCWtGp8DXubMl64JBCUHuv5+N+y2Q=; b=cwTvps9O+obzVzMsSnM0ITkIHloGcZvQ+c7IjJRDkr1EcY5Z2RoI51ajbonaEP2kkl t94fANH5JBeaZjpkLfYoV252Zl/N5fGvrkQ5jGYXzpFeuvZ2q5KUHKjGnAWu/1O7ygZm Kzzh24OEf9X00euqyeDJNH+Isc+ezCQZrwdW0kpGOhwKIxyTeumY3OOkF3o5Mv9VZSVv lw1p6NjJvQsPAxYNzLycnM9yTEBIkBCh8L9YTjg0TQk7BEenw43Amm2sHl4kFSpKbRom THorVy4HgQTk2tuDC0WlAiSyebv12Ja4PLwyBn0bz1R8bUNwLyrd2vJ02iIxURdbj7i8 m1Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=oRQw1FMOdExMekWCWtGp8DXubMl64JBCUHuv5+N+y2Q=; b=YHTuEqMUlU8YhdXh6l/Smr4s6b3AKmz9O+HNlJesii4JWY1VjfDu96UeljaqAnQbFC 6i5LVjksXdu2R9anKvUUSyK8kWVJyrbySMgWivS3G3sWk7/zMZu9vojez/upuYX2gie6 oq/cFayAC9Qi9fBFjU3tpPjmzmm0pfX+DHvriJj428l+4K4Ev3hOtpKGwbhhpIvI5aU+ 29XIOxSGccGNRT8Cm36xOs7mW3Ybo6Flqesb78E+QDXkbAG9PnVBDv+ItSTF2td3ajLH TR5nGvtxk86JDgIoOZOPsqHGhRUxt+H5EQWtdc6NbPn/pCz8IBWV8BGtLHDfRVXRZGss yFFQ== X-Gm-Message-State: AOUpUlECoxJNMkVt9DUDOlXXV9gEocyZqjLH/PprI40xNEUVATs5CSnb h5cysM6s/6qaEzor+YgyOQCm+DCG X-Google-Smtp-Source: AAOMgpeQaDJsj8TNdZFaWbf5BnESnww5YtvXCfTtIli7xnBRMEMLgdV0SYjrLNjqbIlvgfQ3u777hg== X-Received: by 2002:a63:6092:: with SMTP id u140-v6mr5437628pgb.433.1532174871870; Sat, 21 Jul 2018 05:07:51 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:44 +0530 Message-Id: <1532174832-21644-13-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 21 Jul 2018 12:07:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 21 Jul 2018 12:07:52 +0000 (UTC) for IP:'209.85.215.194' DOMAIN:'mail-pg1-f194.google.com' HELO:'mail-pg1-f194.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.194 mail-pg1-f194.google.com 209.85.215.194 mail-pg1-f194.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 12/40] util: mdev: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 21 Jul 2018 12:08:54 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virmdev.c | 53 +++++++++++++++++++-------------------------------= --- 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/src/util/virmdev.c b/src/util/virmdev.c index d7bcb1d..04c9302 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -72,24 +72,23 @@ static int virMediatedDeviceGetSysfsDeviceAPI(virMediatedDevicePtr dev, char **device_api) { - int ret =3D -1; - char *buf =3D NULL; - char *file =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOFREE(char *) file =3D NULL; char *tmp =3D NULL; =20 if (virAsprintf(&file, "%s/mdev_type/device_api", dev->path) < 0) - goto cleanup; + return -1; =20 /* TODO - make this a generic method to access sysfs files for various * kinds of devices */ if (!virFileExists(file)) { virReportSystemError(errno, _("failed to read '%s'"), file); - goto cleanup; + return -1; } =20 if (virFileReadAll(file, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if ((tmp =3D strchr(buf, '\n'))) *tmp =3D '\0'; @@ -97,11 +96,7 @@ virMediatedDeviceGetSysfsDeviceAPI(virMediatedDevicePtr = dev, *device_api =3D buf; buf =3D NULL; =20 - ret =3D 0; - cleanup: - VIR_FREE(file); - VIR_FREE(buf); - return ret; + return 0; } =20 =20 @@ -109,8 +104,7 @@ static int virMediatedDeviceCheckModel(virMediatedDevicePtr dev, virMediatedDeviceModelType model) { - int ret =3D -1; - char *dev_api =3D NULL; + VIR_AUTOFREE(char *) dev_api =3D NULL; int actual_model; =20 if (virMediatedDeviceGetSysfsDeviceAPI(dev, &dev_api) < 0) @@ -123,7 +117,7 @@ virMediatedDeviceCheckModel(virMediatedDevicePtr dev, virReportError(VIR_ERR_INTERNAL_ERROR, _("device API '%s' not supported yet"), dev_api); - goto cleanup; + return -1; } =20 if (actual_model !=3D model) { @@ -132,13 +126,10 @@ virMediatedDeviceCheckModel(virMediatedDevicePtr dev, "device only supports '%s'"), virMediatedDeviceModelTypeToString(model), dev->path, dev_api); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(dev_api); - return ret; + return 0; } =20 =20 @@ -147,7 +138,7 @@ virMediatedDeviceNew(const char *uuidstr, virMediatedDe= viceModelType model) { virMediatedDevicePtr ret =3D NULL; virMediatedDevicePtr dev =3D NULL; - char *sysfspath =3D NULL; + VIR_AUTOFREE(char *) sysfspath =3D NULL; =20 if (!(sysfspath =3D virMediatedDeviceGetSysfsPath(uuidstr))) goto cleanup; @@ -173,7 +164,6 @@ virMediatedDeviceNew(const char *uuidstr, virMediatedDe= viceModelType model) VIR_STEAL_PTR(ret, dev); =20 cleanup: - VIR_FREE(sysfspath); virMediatedDeviceFree(dev); return ret; } @@ -218,34 +208,30 @@ virMediatedDeviceGetPath(virMediatedDevicePtr dev) char * virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr) { - char *result_path =3D NULL; - char *iommu_path =3D NULL; + VIR_AUTOFREE(char *) result_path =3D NULL; + VIR_AUTOFREE(char *) iommu_path =3D NULL; + VIR_AUTOFREE(char *) dev_path =3D virMediatedDeviceGetSysfsPath(uuidst= r); char *vfio_path =3D NULL; - char *dev_path =3D virMediatedDeviceGetSysfsPath(uuidstr); =20 if (!dev_path) return NULL; =20 if (virAsprintf(&iommu_path, "%s/iommu_group", dev_path) < 0) - goto cleanup; + return NULL; =20 if (!virFileExists(iommu_path)) { virReportSystemError(errno, _("failed to access '%s'"), iommu_path= ); - goto cleanup; + return NULL; } =20 if (virFileResolveLink(iommu_path, &result_path) < 0) { virReportSystemError(errno, _("failed to resolve '%s'"), iommu_pat= h); - goto cleanup; + return NULL; } =20 if (virAsprintf(&vfio_path, "/dev/vfio/%s", last_component(result_path= )) < 0) - goto cleanup; + return vfio_path; =20 - cleanup: - VIR_FREE(result_path); - VIR_FREE(iommu_path); - VIR_FREE(dev_path); return vfio_path; } =20 @@ -253,7 +239,7 @@ virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr) int virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr) { - char *vfio_path =3D NULL; + VIR_AUTOFREE(char *) vfio_path =3D NULL; char *group_num_str =3D NULL; unsigned int group_num =3D -1; =20 @@ -263,7 +249,6 @@ virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr) group_num_str =3D last_component(vfio_path); ignore_value(virStrToLong_ui(group_num_str, NULL, 10, &group_num)); =20 - VIR_FREE(vfio_path); return group_num; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175004246824.4396886584407; Sat, 21 Jul 2018 05:10:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 776EA308A943; Sat, 21 Jul 2018 12:10:02 +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 F0EC45B686; Sat, 21 Jul 2018 12:10:01 +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 55BE71841C4B; Sat, 21 Jul 2018 12:10:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8AKN016358 for ; Sat, 21 Jul 2018 08:08:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3BA5EC4A64; Sat, 21 Jul 2018 12:08:10 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3391ECC112 for ; Sat, 21 Jul 2018 12:08:07 +0000 (UTC) Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C8E8C057FA1 for ; Sat, 21 Jul 2018 12:07:55 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id j26-v6so223463pfi.10 for ; Sat, 21 Jul 2018 05:07:55 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=laQQDdmW3u7RpfVtnICPjDsUWhbhhHtFBL9cmOX4WG8=; b=GfnivM8quZGycP4PCIcLZhpq21x6+7q82u72W7Sx25wQBb1QWnYqLcpNHn/Vt0e2Nt lL6hjKQb9BtXwlVNkqnWJpUk6Ad53Bzpz11d5X7kEEvbCZYXo+CzSmUs41rxQSrEDe2i 3igxn7aS1bKw3/UFkmhA+VLoPDGBt3BWr95qzHTCIW47OjPymy77cSrLRux8qtE95L+Q QHX1G8VIDfO+IorbLINhrZ5btCjaCpUW1FFNAakEgYlK6sTMznpZU5cMZdQiLKqgaWD0 dmxBkCygQd2CEULmzgGiuQRJGMm5H998v1+M4gtAowhbCdL/n4omX23/qzU1OK3R36eB rAfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=laQQDdmW3u7RpfVtnICPjDsUWhbhhHtFBL9cmOX4WG8=; b=m2wn0uOoXDa9Tia/miYv1R1PM09Mk2h0XyVtyeP/t9XmSe9kH5SCO7RuYJI+/Niopv G1hwSmPKcpN7Jp8dJSYUR9s9Cj4t+iiFdLluES/e+x3JhHBBhKFaROosD9RfSrHywr0p PPoBvDvQcFivpcPrSrdYx5+AbyT+tDkeJCilyO4aX6BKUqKDfq+mk78xHwXyeJf6kN7g igDkwzB4AXzG0Ev/MGDSdWWdnUXej1TSWdLbhKhy8UnM+O2Z7XAbtucdpNA8l2esajSI /p+K2HS7QeKKxkdiRDjusFsq4Ok2ACnduGDPI6+r5yV3Flol5kt5cmWOgJ+IcxBbf2Tv Og3A== X-Gm-Message-State: AOUpUlGZzBaH4iW3Gn43JEZYnHeVGt7gUVMkVRtIjY3/shFnU/IJx5Yd UCsBnoHAiCjAuYnEM8TLQd4em5HO X-Google-Smtp-Source: AAOMgpfM6EHZdWwdouuED/ECErHtErOYP3mAfQcxICV7+Zs0JkFc8ZA3hIzQORa+AqEAuV30DQdi/Q== X-Received: by 2002:a63:416:: with SMTP id 22-v6mr5439653pge.229.1532174874332; Sat, 21 Jul 2018 05:07:54 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:45 +0530 Message-Id: <1532174832-21644-14-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:07:55 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:07:55 +0000 (UTC) for IP:'209.85.210.195' DOMAIN:'mail-pf1-f195.google.com' HELO:'mail-pf1-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.291 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.210.195 mail-pf1-f195.google.com 209.85.210.195 mail-pf1-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 13/40] util: mdev: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sat, 21 Jul 2018 12:10:03 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virmdev.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/util/virmdev.c b/src/util/virmdev.c index 04c9302..46999bb 100644 --- a/src/util/virmdev.c +++ b/src/util/virmdev.c @@ -137,20 +137,20 @@ virMediatedDevicePtr virMediatedDeviceNew(const char *uuidstr, virMediatedDeviceModelType model) { virMediatedDevicePtr ret =3D NULL; - virMediatedDevicePtr dev =3D NULL; + VIR_AUTOPTR(virMediatedDevice) dev =3D NULL; VIR_AUTOFREE(char *) sysfspath =3D NULL; =20 if (!(sysfspath =3D virMediatedDeviceGetSysfsPath(uuidstr))) - goto cleanup; + return NULL; =20 if (!virFileExists(sysfspath)) { virReportError(VIR_ERR_DEVICE_MISSING, _("mediated device '%s' not found"), uuidstr); - goto cleanup; + return NULL; } =20 if (VIR_ALLOC(dev) < 0) - goto cleanup; + return NULL; =20 VIR_STEAL_PTR(dev->path, sysfspath); =20 @@ -158,13 +158,11 @@ virMediatedDeviceNew(const char *uuidstr, virMediated= DeviceModelType model) * supported mediated device's API. */ if (virMediatedDeviceCheckModel(dev, model)) - goto cleanup; + return NULL; =20 dev->model =3D model; VIR_STEAL_PTR(ret, dev); =20 - cleanup: - virMediatedDeviceFree(dev); return ret; } =20 @@ -372,8 +370,7 @@ void virMediatedDeviceListDel(virMediatedDeviceListPtr list, virMediatedDevicePtr dev) { - virMediatedDevicePtr ret =3D virMediatedDeviceListSteal(list, dev); - virMediatedDeviceFree(ret); + VIR_AUTOPTR(virMediatedDevice) ret =3D virMediatedDeviceListSteal(list= , dev); } =20 =20 @@ -494,23 +491,22 @@ int virMediatedDeviceTypeReadAttrs(const char *sysfspath, virMediatedDeviceTypePtr *type) { - int ret =3D -1; - virMediatedDeviceTypePtr tmp =3D NULL; + VIR_AUTOPTR(virMediatedDeviceType) tmp =3D NULL; =20 #define MDEV_GET_SYSFS_ATTR(attr, dst, cb, optional) \ do { \ int rc; \ if ((rc =3D cb(dst, "%s/%s", sysfspath, attr)) < 0) { \ if (rc !=3D -2 || !optional) \ - goto cleanup; \ + return 0; \ } \ } while (0) =20 if (VIR_ALLOC(tmp) < 0) - goto cleanup; + return -1; =20 if (VIR_STRDUP(tmp->id, last_component(sysfspath)) < 0) - goto cleanup; + return -1; =20 /* @name sysfs attribute is optional, so getting ENOENT is fine */ MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString, true); @@ -522,8 +518,6 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath, #undef MDEV_GET_SYSFS_ATTR =20 VIR_STEAL_PTR(*type, tmp); - ret =3D 0; - cleanup: - virMediatedDeviceTypeFree(tmp); - return ret; + + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175033184658.8799959395456; Sat, 21 Jul 2018 05:10:33 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 62AF987644; Sat, 21 Jul 2018 12:10:26 +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 227E55C20D; Sat, 21 Jul 2018 12:10:25 +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 D0A051841C5D; Sat, 21 Jul 2018 12:10:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8BMe016366 for ; Sat, 21 Jul 2018 08:08:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id A3B442015E43; Sat, 21 Jul 2018 12:08:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 989E42015E42 for ; Sat, 21 Jul 2018 12:08:07 +0000 (UTC) Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 35BE83082A2E for ; Sat, 21 Jul 2018 12:07:57 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id f1-v6so8956515pgq.12 for ; Sat, 21 Jul 2018 05:07:57 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=+OcS+3H6Z9W2Hml2rQOYhyeKSjvX/Q4ErTlGwNOtOeA=; b=oqeYFzsNMWdnb5pMz6wqEKgPUJw7a7g/rKUvA7rYN8Xofuthi8TU6+bFKq3qwq0pPq rervWWi+g7LIQHBnPL1rBfm04aohUEw7llZXCX/s9IMqwkuBS0QCIEbnoFEwJRp65Sbt 2vkpA46Iw2BnskMM0XrIsHKSkhFmJnXekvglFFMXOMm0DLgBrV4vuKCyoeBB7mQAem3U tuxICo+WvTPp369Oz/BH/gy0eOMCGqS0kLYt8QTVN6JPY78d/8UOumL9EqDk8QDXjdZo mO8PV3qZwuK1a7ZxZimLtJxActXbDZootXieQJz3/Wj51kgFLKNyilVWN3yIdMDrCZqk Hzxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+OcS+3H6Z9W2Hml2rQOYhyeKSjvX/Q4ErTlGwNOtOeA=; b=d1FQZkTAgyZNan6V3ZDjbDOntqmcJAW0+7haHoMX+P7yEJrZiHwIQkqpZty9mkx/MP KDck7Atv23WXwOy6gz39nzLUEIrd01urrIgSI/OksW0+yeJILzfc7zV1BCblH/w9wnp2 u9+OSYGyF4WGxzvfhkP6ZXFiWLdQ5Vi616ynsCBxQv90+wor6AVpVZsO71yngdItYDWb XrhdXxtS16v77JsZ3XDbCHNVPv1vYsqkg/QesZaqI2dg6ggGeOXfIs/E4+JCAq+kUYWN qgVTug1WD+vNeAPAcUb2o4ehqV3qj3ajjqKp3n6jEarupTQ9JGxWNnTCqxuUiVWcd5+8 oyNg== X-Gm-Message-State: AOUpUlGjUFhnzoG+AFo6sT5PW4W7YEKVQoM2tjvljtZalazkPW1jInmK HFoQfXxkMIll60NQ7aYUVEo467IC X-Google-Smtp-Source: AAOMgpdjOEUBPT8URddjvV6JunIQgfXf4QgY2JNsCDWbMbs9fbmEpzU6tbBkZnZEQNN1EU+Yjtl+Qg== X-Received: by 2002:a62:3545:: with SMTP id c66-v6mr5833193pfa.63.1532174876416; Sat, 21 Jul 2018 05:07:56 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:46 +0530 Message-Id: <1532174832-21644-15-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 21 Jul 2018 12:07:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 21 Jul 2018 12:07:57 +0000 (UTC) for IP:'209.85.215.173' DOMAIN:'mail-pg1-f173.google.com' HELO:'mail-pg1-f173.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.173 mail-pg1-f173.google.com 209.85.215.173 mail-pg1-f173.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 14/40] util: firewall: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:10:32 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virFirewallPtr is declared using VIR_AUTOPTR, the function virFirewallFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virfirewall.c | 1 - src/util/virfirewall.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index 10c370a..dfd792f 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -27,7 +27,6 @@ =20 #include =20 -#include "viralloc.h" #include "virfirewallpriv.h" #include "virerror.h" #include "virutil.h" diff --git a/src/util/virfirewall.h b/src/util/virfirewall.h index b04ab48..e024e88 100644 --- a/src/util/virfirewall.h +++ b/src/util/virfirewall.h @@ -25,6 +25,7 @@ # define __VIR_FIREWALL_H__ =20 # include "internal.h" +# include "viralloc.h" =20 typedef struct _virFirewall virFirewall; typedef virFirewall *virFirewallPtr; @@ -116,4 +117,6 @@ int virFirewallApply(virFirewallPtr firewall); =20 void virFirewallSetLockOverride(bool avoid); =20 +VIR_DEFINE_AUTOPTR_FUNC(virFirewall, virFirewallFree) + #endif /* __VIR_FIREWALL_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175054541171.46180362048267; Sat, 21 Jul 2018 05:10:54 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 288F985545; Sat, 21 Jul 2018 12:10: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 C513E10694CC; Sat, 21 Jul 2018 12:10:47 +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 74D8E4EE16; Sat, 21 Jul 2018 12:10:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8DtK016377 for ; Sat, 21 Jul 2018 08:08:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id E2894308BDB7; Sat, 21 Jul 2018 12:08:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D6DCA308BDB1 for ; Sat, 21 Jul 2018 12:08:10 +0000 (UTC) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48F7D552C7 for ; Sat, 21 Jul 2018 12:07:59 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id f1-v6so8956601pgq.12 for ; Sat, 21 Jul 2018 05:07:59 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:07:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=aJpbopE0VruhbIcHy40PuopspIICI4X4Z3WOsG8kqxk=; b=klTh0xBPku1aQN48fZ03BJITYpI8YGba5CYWfH7EVbGfAxmGqEmagVDEHwaZKADwo0 NoCS6VytgxsI9DchzTo/JGwTPNklljPvBLtifuPSQWLi8gcYZKXXQKBDEhCc0eAjJ4Lw XY/jd/9Yjte9aXw1FLYB4O3fqfC5cW0o3i0HmW91B7ZW+BOA5tbuyW7bj9wR9Zb1YP9Z pSKoy7M1FhlSM9BR4prPdyLkVv39XwZrg3/+uk/I7pSLXzjocWJadrmES2XovS5T+VgD zrb2gysXz7qZZk3t6r34jiEi82+AWXW/BdkW6q5a+AGLuO0iBwmE18n5ygVGqUEBieAP 9ryA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=aJpbopE0VruhbIcHy40PuopspIICI4X4Z3WOsG8kqxk=; b=t5K7xFf03gS6UlDncDOyr7XxpNC7W5g05stbqlN3n19uZsTO/aKZL55GgJbQI5Wl+A uY7Q8wMKtPjtMEEfVOjEDcwk/U4RzE8XolYguAnGOKaBLHk0XZuxta6WC9HM16qGEtvs bzZN3OLjk64wioDQF29tVALXcqDDsLr6aYRc4kYi79Yts4YTAhSqKaBOVED1GiZ005KW vzZohpxx2RsYhwckMM37jYhRsItw/aLYC+PAIB6YQErD01Qm99Ceydrdxof9PlLzq0w4 T92Dsn67pNQjFOTr0F5YKh2Ty0sPFIZERjBAOf/Ll4yjv/pn/A6vvYmbsduQVhkHG1WU ylng== X-Gm-Message-State: AOUpUlEapy1Z720vURVSl0aBSIxp57+HslHsECtne0drnVjHx7YlOecn xqwsecO6eQ0f8Y+ohUWhSiLvq+Eg X-Google-Smtp-Source: AAOMgpd6HAo2nAkvXAo92hUmf4ZpJmVwjLr1CBIMbNCsE5WEokIHxkt7Apcq4h6Oxi/2dA1ipRwOQQ== X-Received: by 2002:a62:5543:: with SMTP id j64-v6mr5837080pfb.188.1532174878597; Sat, 21 Jul 2018 05:07:58 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:47 +0530 Message-Id: <1532174832-21644-16-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 21 Jul 2018 12:07:59 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 21 Jul 2018 12:07:59 +0000 (UTC) for IP:'209.85.215.179' DOMAIN:'mail-pg1-f179.google.com' HELO:'mail-pg1-f179.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.179 mail-pg1-f179.google.com 209.85.215.179 mail-pg1-f179.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 15/40] util: firewall: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 21 Jul 2018 12:10:53 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virfirewall.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index dfd792f..b4a4d06 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -511,7 +511,7 @@ void virFirewallRuleAddArgFormat(virFirewallPtr firewal= l, virFirewallRulePtr rule, const char *fmt, ...) { - char *arg; + VIR_AUTOFREE(char *) arg =3D NULL; va_list list; =20 VIR_FIREWALL_RULE_RETURN_IF_ERROR(firewall, rule); @@ -525,13 +525,11 @@ void virFirewallRuleAddArgFormat(virFirewallPtr firew= all, =20 va_end(list); =20 - VIR_FREE(arg); return; =20 no_memory: firewall->err =3D ENOMEM; va_end(list); - VIR_FREE(arg); } =20 =20 @@ -678,7 +676,7 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, virCommandPtr cmd =3D NULL; int status; int ret =3D -1; - char *error =3D NULL; + VIR_AUTOFREE(char *) error =3D NULL; =20 if (!bin) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -702,11 +700,10 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, if (ignoreErrors) { VIR_DEBUG("Ignoring error running command"); } else { - char *args =3D virCommandToString(cmd); + VIR_AUTOFREE(char *) args =3D virCommandToString(cmd); virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to apply firewall rules %s: %s"), NULLSTR(args), NULLSTR(error)); - VIR_FREE(args); VIR_FREE(*output); goto cleanup; } @@ -714,7 +711,6 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, =20 ret =3D 0; cleanup: - VIR_FREE(error); virCommandFree(cmd); return ret; } @@ -807,12 +803,11 @@ virFirewallApplyRule(virFirewallPtr firewall, virFirewallRulePtr rule, bool ignoreErrors) { - char *output =3D NULL; + VIR_AUTOFREE(char *) output =3D NULL; + VIR_AUTOFREE(char *) str =3D virFirewallRuleToString(rule); char **lines =3D NULL; int ret =3D -1; - char *str =3D virFirewallRuleToString(rule); VIR_INFO("Applying rule '%s'", NULLSTR(str)); - VIR_FREE(str); =20 if (rule->ignoreErrors) ignoreErrors =3D rule->ignoreErrors; @@ -857,7 +852,6 @@ virFirewallApplyRule(virFirewallPtr firewall, ret =3D 0; cleanup: virStringListFree(lines); - VIR_FREE(output); return ret; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174953758981.4744100117653; Sat, 21 Jul 2018 05:09:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F1E9A30832E1; Sat, 21 Jul 2018 12:09:10 +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 BCBE52016207; Sat, 21 Jul 2018 12:09:10 +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 76B0B4EE1F; Sat, 21 Jul 2018 12:09:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8DNc016376 for ; Sat, 21 Jul 2018 08:08:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id E2813308BDB4; Sat, 21 Jul 2018 12:08:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D7740308BDB3 for ; Sat, 21 Jul 2018 12:08:13 +0000 (UTC) Received: from mail-pl0-f53.google.com (mail-pl0-f53.google.com [209.85.160.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A55AE356F0 for ; Sat, 21 Jul 2018 12:08:02 +0000 (UTC) Received: by mail-pl0-f53.google.com with SMTP id 6-v6so6311125plb.0 for ; Sat, 21 Jul 2018 05:08:02 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.07.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=YlnOWIenqsvgSYi5U/sHoybu4wG23RbKR00iHdAAKiw=; b=nbdqHTH4aSsgct9ydLNbxlSo8scubohNPz+kuJ+RUkor2OYtrAHwmvUmsef3H50Cyx 80W8c1kp2fnkSXezUdrbc5MFVBSq6OEgk8RcrUmbA7+EYryCIZaVBU++QQN+RfXC1itm RHxpbWgSVqciGkgiXUpGfZWsbyL9I+M53IjuY3ryU3yEsWl7FPL4+IZnN5dLegItn1zC KLbTPDMdAVRkqpvH8eAZWidqSsOh6UmPUZ2kMjqBzJxUwoKWTq9UtkeLWEKKCvIbiunH JpkQQuNtWlHJUFWK1QK+3rHrgsulM+MU2FUT4zzydSakiFW8VhjS+y13Ezs+CrjvcxUG bSvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=YlnOWIenqsvgSYi5U/sHoybu4wG23RbKR00iHdAAKiw=; b=uGPMLhPpQ4Qug6axQptyDqi9+DdWJsZm0NRxaU0vPKqWguvPPkQMXPoOA0euAMPeg7 AEi97lNgC9vGYWS6ZcmzCrEGKzzOc5k94O2Vfghci5AdD9CCSmprDtoPwj0p3JcAE95j +A5QD0PsaNcicUJzmOmQIc7VsOr68N4Fk/ozyydidAzWeF1H/KJHgp0QCuv2n1C0dzxm VpkJ/Aa2pEDWIKKf4qPlthTSmr3jaKs/kkzu0W/Ld0MwZ0vRCIgQv1cjFyJzBO27aAu3 TPDHBdAVGtpRmlnD/PZ+dmF98ki8KkRu90THsq7SN3u+V8HY66uQKnK/mG3UL9afZJsY I7AQ== X-Gm-Message-State: AOUpUlEemOZwbLeTZJfa+znyfFf1pqnpoqAPFzYiYeG/WbR0RGBU0A55 6tb7g74SlZ9yqWg2OM6Sep+Th15e X-Google-Smtp-Source: AAOMgpeHMmGdeOk+VnU6rxPpSxm8ZoLPs7MIwyJeJXem7ii8I2XThLc3pEITI8oloihEJ1Mkk12yJA== X-Received: by 2002:a17:902:33c2:: with SMTP id b60-v6mr5722656plc.11.1532174881928; Sat, 21 Jul 2018 05:08:01 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:48 +0530 Message-Id: <1532174832-21644-17-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 21 Jul 2018 12:08:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 21 Jul 2018 12:08:02 +0000 (UTC) for IP:'209.85.160.53' DOMAIN:'mail-pl0-f53.google.com' HELO:'mail-pl0-f53.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.160.53 mail-pl0-f53.google.com 209.85.160.53 mail-pl0-f53.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 16/40] util: firewall: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 21 Jul 2018 12:09:12 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virfirewall.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/util/virfirewall.c b/src/util/virfirewall.c index b4a4d06..c786d76 100644 --- a/src/util/virfirewall.c +++ b/src/util/virfirewall.c @@ -119,14 +119,13 @@ virFirewallCheckUpdateLock(bool *lockflag, const char *const*args) { int status; /* Ignore failed commands without logging them */ - virCommandPtr cmd =3D virCommandNewArgs(args); + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgs(args); if (virCommandRun(cmd, &status) < 0 || status) { VIR_INFO("locking not supported by %s", args[0]); } else { VIR_INFO("using locking for %s", args[0]); *lockflag =3D true; } - virCommandFree(cmd); } =20 static void @@ -673,16 +672,15 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, { size_t i; const char *bin =3D virFirewallLayerCommandTypeToString(rule->layer); - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; int status; - int ret =3D -1; VIR_AUTOFREE(char *) error =3D NULL; =20 if (!bin) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown firewall layer %d"), rule->layer); - goto cleanup; + return -1; } =20 cmd =3D virCommandNewArgList(bin, NULL); @@ -694,7 +692,7 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, virCommandSetErrorBuffer(cmd, &error); =20 if (virCommandRun(cmd, &status) < 0) - goto cleanup; + return -1; =20 if (status !=3D 0) { if (ignoreErrors) { @@ -705,14 +703,11 @@ virFirewallApplyRuleDirect(virFirewallRulePtr rule, _("Failed to apply firewall rules %s: %s"), NULLSTR(args), NULLSTR(error)); VIR_FREE(*output); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -805,8 +800,7 @@ virFirewallApplyRule(virFirewallPtr firewall, { VIR_AUTOFREE(char *) output =3D NULL; VIR_AUTOFREE(char *) str =3D virFirewallRuleToString(rule); - char **lines =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virString) lines =3D NULL; VIR_INFO("Applying rule '%s'", NULLSTR(str)); =20 if (rule->ignoreErrors) @@ -831,28 +825,25 @@ virFirewallApplyRule(virFirewallPtr firewall, =20 if (rule->queryCB && output) { if (!(lines =3D virStringSplit(output, "\n", -1))) - goto cleanup; + return -1; =20 VIR_DEBUG("Invoking query %p with '%s'", rule->queryCB, output); if (rule->queryCB(firewall, (const char *const *)lines, rule->quer= yOpaque) < 0) - goto cleanup; + return -1; =20 if (firewall->err =3D=3D ENOMEM) { virReportOOMError(); - goto cleanup; + return -1; } if (firewall->err) { virReportSystemError(firewall->err, "%s", _("Unable to create rule")); - goto cleanup; + return -1; } =20 } =20 - ret =3D 0; - cleanup: - virStringListFree(lines); - return ret; + return 0; } =20 static int @@ -926,7 +917,7 @@ virFirewallApply(virFirewallPtr firewall) if (virFirewallApplyGroup(firewall, i) < 0) { VIR_DEBUG("Rolling back groups up to %zu for %p", i, firewall); size_t first =3D i; - virErrorPtr saved_error =3D virSaveLastError(); + VIR_AUTOPTR(virError) saved_error =3D virSaveLastError(); =20 /* * Look at any inheritance markers to figure out @@ -947,7 +938,6 @@ virFirewallApply(virFirewallPtr firewall) } =20 virSetError(saved_error); - virFreeError(saved_error); VIR_DEBUG("Done rolling back groups for %p", firewall); goto cleanup; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174977169577.5634934658144; Sat, 21 Jul 2018 05:09:37 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id DCC7A5F728; Sat, 21 Jul 2018 12:09:35 +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 878B9608F2; Sat, 21 Jul 2018 12:09:34 +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 012E14EE0F; Sat, 21 Jul 2018 12:09:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8Gwn016397 for ; Sat, 21 Jul 2018 08:08:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id B45A4C4A64; Sat, 21 Jul 2018 12:08:16 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB41CCC112 for ; Sat, 21 Jul 2018 12:08:16 +0000 (UTC) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3495307C946 for ; Sat, 21 Jul 2018 12:08:05 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id e6-v6so8969000pgv.2 for ; Sat, 21 Jul 2018 05:08:05 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=SscAtlEfcPdzxvglFSeVF6kgcJj+ZEM1gHFKxb2XuCk=; b=Rs+WkyLtwe/U/jw+I+R4TrCqt4URD1hPGgGx87atxToM+cLXdwkdFZeGytwBmWOmxX snlQJvgHRnGLTkppWE7s56s6S51bCLSUEjLy/XpnzeDF921+cDdXY9ol5eFpEfOskEsu /6+I7gw67yude01a3Oprs95dzhCbw6TfTWsfcv5hvmf237vqrVwcPik/15wexPBc3uAN bjS55u17bC7pb4c019ZzW4Mzo1o4bSqwf0f9vUqW308JpW7kOJFZxd/hkNvk/w5btxbG grh2cXVoxgk79UELSwGohoXhHkmKOjzyjuAScy1fXI6tOyLOg2GyVEWHzK88dkE9ddGH jvtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=SscAtlEfcPdzxvglFSeVF6kgcJj+ZEM1gHFKxb2XuCk=; b=Kg3xRL9P2wW7sZbDMJjVL3+LqX4bd/QZJVkWXYBcyQcoepxFI7rUjmfFlx0K05JASp IfCggD9gXFMX61IGl3Y3AasDmMONCuoSAeXDQg4O0X1w+pmqv8KEdm9+JY0uFHD+hWKm w8Oud6wL/0fxVwk0Lca3RChlux1ypVCQ1zfd5LeCitymORxzFC+Bey/OTrFKWMrACFif Wup0y5wClFg9pySTjCKtMh218lDtzM9GXcVJApTYd8AoP4W5aJbcZv1MGaShAtdhEQLY cl3lOVjpuWscxiqmHcwl+mTIJW+8anM7v3ScpZl2uewt75kRvEnkhJ+whIT360WV2wYX L0jg== X-Gm-Message-State: AOUpUlFmwqFmhYB0B4ajXdvwePAZ8YbWtNywX2BMyxbp0MIkc8vj40Dd MyB/yht6lVSUfZMYP4WbNN68IaTt X-Google-Smtp-Source: AAOMgpcwtk1LdLbVXd0xPxxthPE4AkzJNUcUPEU3kig8mfcQl2OtMllPQ/7sPNWHQ5ZdgPFtGwoVhQ== X-Received: by 2002:a62:3ece:: with SMTP id y75-v6mr5885649pfj.7.1532174885074; Sat, 21 Jul 2018 05:08:05 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:49 +0530 Message-Id: <1532174832-21644-18-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 21 Jul 2018 12:08:05 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 21 Jul 2018 12:08:05 +0000 (UTC) for IP:'209.85.215.170' DOMAIN:'mail-pg1-f170.google.com' HELO:'mail-pg1-f170.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.170 mail-pg1-f170.google.com 209.85.215.170 mail-pg1-f170.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 17/40] util: hook: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 21 Jul 2018 12:09:36 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virhook.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/util/virhook.c b/src/util/virhook.c index facd74a..51f0eb5 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -122,8 +122,7 @@ static int virHooksFound =3D -1; static int virHookCheck(int no, const char *driver) { - char *path; - int ret; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (driver =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -139,18 +138,15 @@ virHookCheck(int no, const char *driver) } =20 if (!virFileExists(path)) { - ret =3D 0; VIR_DEBUG("No hook script %s", path); + return 0; } else if (!virFileIsExecutable(path)) { - ret =3D 0; VIR_WARN("Non-executable hook script %s", path); + return 0; } else { - ret =3D 1; VIR_DEBUG("Found hook script %s", path); + return 1; } - - VIR_FREE(path); - return ret; } =20 /* @@ -233,7 +229,7 @@ virHookCall(int driver, char **output) { int ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; virCommandPtr cmd; const char *drvstr; const char *opstr; @@ -318,7 +314,5 @@ virHookCall(int driver, =20 virCommandFree(cmd); =20 - VIR_FREE(path); - return ret; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153217508015396.91683347333799; Sat, 21 Jul 2018 05:11:20 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 8667A307C701; Sat, 21 Jul 2018 12:11:12 +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 4992A26E60; Sat, 21 Jul 2018 12:11:11 +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 EC0271841C5D; Sat, 21 Jul 2018 12:11:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8JxR016414 for ; Sat, 21 Jul 2018 08:08:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 63F71CC105; Sat, 21 Jul 2018 12:08:19 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5CFCFC4A64 for ; Sat, 21 Jul 2018 12:08:19 +0000 (UTC) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88BAA30820DD for ; Sat, 21 Jul 2018 12:08:08 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id z8-v6so8965847pgu.8 for ; Sat, 21 Jul 2018 05:08:08 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=O/XIIIhR7SR2c+5o76IQ9rVKE8OhI2cWC2IdCpQcQ4I=; b=NXLbnf4184fI5CKHw5YzC9uF5S4nl+F0lPhjjVMSz6HcHerW+jRaLqwiTg0trTcdU1 vcsGlxXQVeIRpMnvNQa3XRsWjxfvHtSpt7kbvDDvWGk0iBwT4JxqXgZlysrLdybHB+Zr RJNZrsDH27BxjXJD9Q01MLkcdCTPGLnvdOETuLmASWhJXo+bNzDx23Sac+zLV1Kr6yAq 15XoV9RI5mu5zZCaUb3oCm+nwtNZLPoVLHqfrc35W/Cnqcy7kkQTaF7IC/pizSJlt3Po UPXVPyiiXV9lrQcsfetXqntdI5j6jZI0OtUHfDZMicTnT+ViAWIGjMUwtIEz7ObyrqcK uWFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=O/XIIIhR7SR2c+5o76IQ9rVKE8OhI2cWC2IdCpQcQ4I=; b=Nr2DYVSXXOOzRDR1vgQp8CaiUIiGxCPnjzCeOK77AnLvwbFpRfUXR6msBeRavnkyym l8ZrDoUy2jIluObtqk3y1hgGq33DQjGUdJClndIRvLrDNtIH9YS+CHcg5I1dcEh4xdut +k1PlYLcJGZgVCK1baAmwbGAzbfUIXlNPnGkdU1aONROqu3/0c79qC/AUdfE6qOEn9Vu Kr/r8rMK0JzGsoWcOGZOlNxpugoLqoFzsvferSVP0N6EUc6X11EbSLszNmTW3xcMO5r0 +WuN6/KnDpywQ5YrlJtLboFIsIygEb0nD2fxHKmrT7klAD/Ikl68ApYEqftsjAccUYwJ RWLg== X-Gm-Message-State: AOUpUlHeIgzFguc7+eIdAwj15hUwu8w6ODU0roUSR4miydNh9mSqS7NS CCp/uM4ez3ZBeIWJioVxr3QFXmxV X-Google-Smtp-Source: AAOMgpdTHAPv9DlHJ+87cQLRNBmjG/Xz1kN/WtyhHqr+whx/szK0srdb8gl+o0yjhRHwgFYhq3fxSw== X-Received: by 2002:a62:a3d1:: with SMTP id q78-v6mr5806109pfl.5.1532174887873; Sat, 21 Jul 2018 05:08:07 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:50 +0530 Message-Id: <1532174832-21644-19-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 21 Jul 2018 12:08:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 21 Jul 2018 12:08:08 +0000 (UTC) for IP:'209.85.215.177' DOMAIN:'mail-pg1-f177.google.com' HELO:'mail-pg1-f177.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.177 mail-pg1-f177.google.com 209.85.215.177 mail-pg1-f177.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 18/40] util: hook: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 21 Jul 2018 12:11:19 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virhook.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/virhook.c b/src/util/virhook.c index 51f0eb5..de80947 100644 --- a/src/util/virhook.c +++ b/src/util/virhook.c @@ -230,7 +230,7 @@ virHookCall(int driver, { int ret; VIR_AUTOFREE(char *) path =3D NULL; - virCommandPtr cmd; + VIR_AUTOPTR(virCommand) cmd =3D NULL; const char *drvstr; const char *opstr; const char *subopstr; @@ -312,7 +312,5 @@ virHookCall(int driver, virGetLastErrorMessage()); } =20 - virCommandFree(cmd); - return ret; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175097906316.4856673289112; Sat, 21 Jul 2018 05:11:37 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B67CE356DC; Sat, 21 Jul 2018 12:11:36 +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 7BFA516EFE; Sat, 21 Jul 2018 12:11:35 +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 2FFE94EE12; Sat, 21 Jul 2018 12:11:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8Mja016424 for ; Sat, 21 Jul 2018 08:08:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id CF318CC105; Sat, 21 Jul 2018 12:08:22 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C8121C4A64 for ; Sat, 21 Jul 2018 12:08:22 +0000 (UTC) Received: from mail-pl0-f44.google.com (mail-pl0-f44.google.com [209.85.160.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1481285A02 for ; Sat, 21 Jul 2018 12:08:12 +0000 (UTC) Received: by mail-pl0-f44.google.com with SMTP id 94-v6so6300009ple.12 for ; Sat, 21 Jul 2018 05:08:12 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=IeWcnShwSf4Q5+CZOnFvEVy4YuGOGea+GiGRzmsmPog=; b=UMhTSKwsThHzWOwRAW9KAPkx/lzylA8VqmiZCv4NnxqIKBu/w5vYa1SKk5r3vx7dgk NDKK6cE1K6KxyhzZkW/idvjOP39khhWzNoHS0mo+zo/KbAwlPtmdifVI6tK1lhDPoT7V Wh4A8D+h4PbaQRtm+xQMSYvyemlAWmVvCGdPu3vD+OWkk9spX7t56MjxwCQf/gVVwmSe A+HnzT6hwKa+os3E4F8oLCzi/hX0Ndjw3C5mS6S2TU91XmKGZ9CAaQsHeSiwr6HkAGX/ STpoLFKtLPoU/FZ06TutWArGkksx96hdd6I9at/Z2XwpP/oGdHG23Lg6Ju6rAQzlvmBE WP0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=IeWcnShwSf4Q5+CZOnFvEVy4YuGOGea+GiGRzmsmPog=; b=pv7Nkm2QVyO8PU8duMqwGjh3a10ltncfLDputxnledBFLeVFFYYVLQK4jc650IZthW //Y4gRShx7bj5RVcrPeUhuWlmW7FLWJoX0SQIu/5CVbmArSJlhTzonDEJJUkikCXWrH5 PAgAwhTKVDEZlkhj/H6nvwjQBUP6BXqHJagZkr6U7dfow1igoDtZFQOUSo+goXjvuRdA ID22o8xxSpPBx28MM7+XrsmqrTetJyj1HrvPUHdH3/LtYSpuf6X2gAeyQriL6OFeCmFX wZ4o6sFLfwfoVWidbRAxcAo6vjy9kG/mg0/AtQEhoS1Fv6opROTxzKBocwfnIO66/g2L ddoA== X-Gm-Message-State: AOUpUlHKVFYfVK+ojjJ8cmHpEZH2caUNUl/AYqiA6Hx4Bn76vr5t2Pbf zI8kNcRqcJ6lVoyYdT9hlZmiFr/S X-Google-Smtp-Source: AAOMgpeIF3IFLBMmGh+28Hkxlcb4IxyMNG/klQBIfPFIo6qrDdM1Fq8sHI+iChvKkJ4v2CrS3JIaHQ== X-Received: by 2002:a17:902:b594:: with SMTP id a20-v6mr5730869pls.140.1532174891320; Sat, 21 Jul 2018 05:08:11 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:51 +0530 Message-Id: <1532174832-21644-20-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:08:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:08:12 +0000 (UTC) for IP:'209.85.160.44' DOMAIN:'mail-pl0-f44.google.com' HELO:'mail-pl0-f44.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.160.44 mail-pl0-f44.google.com 209.85.160.44 mail-pl0-f44.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 19/40] util: pci: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 21 Jul 2018 12:11:37 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When variables of type virPCIDevicePtr and virPCIEDeviceInfoPtr are declared using VIR_AUTOPTR, the functions virPCIDeviceFree and virPCIEDeviceInfoFree, respectively, will be run automatically on them when they go out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virpci.c | 1 - src/util/virpci.h | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 8d02366..a606462 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -39,7 +39,6 @@ =20 #include "dirname.h" #include "virlog.h" -#include "viralloc.h" #include "vircommand.h" #include "virerror.h" #include "virfile.h" diff --git a/src/util/virpci.h b/src/util/virpci.h index 794b7e5..8fc8716 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -28,6 +28,7 @@ # include "virmdev.h" # include "virobject.h" # include "virutil.h" +# include "viralloc.h" =20 typedef struct _virPCIDevice virPCIDevice; typedef virPCIDevice *virPCIDevicePtr; @@ -253,4 +254,7 @@ void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev); ssize_t virPCIGetMdevTypes(const char *sysfspath, virMediatedDeviceType ***types); =20 +VIR_DEFINE_AUTOPTR_FUNC(virPCIDevice, virPCIDeviceFree) +VIR_DEFINE_AUTOPTR_FUNC(virPCIEDeviceInfo, virPCIEDeviceInfoFree) + #endif /* __VIR_PCI_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175007117666.3789090643234; Sat, 21 Jul 2018 05:10:07 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 829ECC057FA1; Sat, 21 Jul 2018 12:09:59 +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 411715C20D; Sat, 21 Jul 2018 12:09:58 +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 E3CE74EE10; Sat, 21 Jul 2018 12:09:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8SeE016441 for ; Sat, 21 Jul 2018 08:08:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2F5B310694C2; Sat, 21 Jul 2018 12:08:28 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 27815100164C for ; Sat, 21 Jul 2018 12:08:26 +0000 (UTC) Received: from mail-pl0-f65.google.com (mail-pl0-f65.google.com [209.85.160.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B07563084042 for ; Sat, 21 Jul 2018 12:08:14 +0000 (UTC) Received: by mail-pl0-f65.google.com with SMTP id t17-v6so3749467ply.13 for ; Sat, 21 Jul 2018 05:08:14 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=2TKu+iM3xmwUCZZg37xDF/xQBd5PNg+RQk5RyaeZflA=; b=YpgK9rq6b4of2ES7nc6HbbMS156nBUWD3TLkOTAjw8J7y52/41Z7pCH1SLAbR1TdrM ulF4qXOhl30ocuRoxjZcPG7RClV7qqB8Ty/X3DyDX5kWTc/M12LXm10XQxu6XvJYvWZ9 2xPfnjyWIlzGVZt9hqwpiO6+82CUQvk5m/QFeVJ5hOeKTmj9DjNXkWi3HaQRrotwvk2u g2rjgEog2DgdO+PuhjnJBDT8RdJTklUG30LIf+oGTI48A4AEOb52+wpxhvPiHzqjegdP 7aRfpL4N0M8hOqME69rawWpAf+aqr2mcD+IOJuKfOTqnNTRrHLrG1KVhDBVwRl6I3Yje Qp9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=2TKu+iM3xmwUCZZg37xDF/xQBd5PNg+RQk5RyaeZflA=; b=LsOxRQbR8xjHh3WLqGtKBsxAbK7ndVAn06m4vO04TDBdhx47oUujDYcl6B7SBPfQ9P tWeHy/n1uAVo39tyoA5TgZzNMdK/qrBxhYJkplHJbO17mHSHHUBg7wSvKh/wahRiANDy AsJ5wG7HYSSDHVkneVYNxNeACV8kiRn2Q99sZ5R1AFQHSVhWS9xGnRxaO2/drCtKo8Y4 Ol/r9xcwV+KKn6pt4embB6d2QMjIlVezAIZaID0WnaUppc4U/bpfnkv4fAauEHh51jP3 Pys0c2VLHEymuiPWGUZITdZZyxBbpmVeFn5iEDtdgiFYcs3XQ/bpgQ2KvIwsQGpBDsWb Z84g== X-Gm-Message-State: AOUpUlEMnpMCBfZn0K8g5OnIVvQRJpSN4H2wsG+8DWvVeQ8E7aun3FSr HOqZ/4EpB7G+IxEgRDEZvfZpaK1d X-Google-Smtp-Source: AAOMgpf6lEkEblI/779uQ6aNl73S0T5FEBQZuAe15/sU7tjOn8UkVW9TFq7AB00vE4Tz4A3xNep7vQ== X-Received: by 2002:a17:902:5a83:: with SMTP id r3-v6mr5571444pli.78.1532174893921; Sat, 21 Jul 2018 05:08:13 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:52 +0530 Message-Id: <1532174832-21644-21-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sat, 21 Jul 2018 12:08:14 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sat, 21 Jul 2018 12:08:14 +0000 (UTC) for IP:'209.85.160.65' DOMAIN:'mail-pl0-f65.google.com' HELO:'mail-pl0-f65.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.65 mail-pl0-f65.google.com 209.85.160.65 mail-pl0-f65.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 20/40] util: pci: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:10:06 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virpci.c | 271 ++++++++++++++++++--------------------------------= ---- 1 file changed, 87 insertions(+), 184 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index a606462..1f6ac0b 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -253,7 +253,7 @@ int virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev, char **path, char **= name) { int ret =3D -1; - char *drvlink =3D NULL; + VIR_AUTOFREE(char *) drvlink =3D NULL; =20 *path =3D *name =3D NULL; /* drvlink =3D "/sys/bus/pci/dddd:bb:ss.ff/driver" */ @@ -285,7 +285,6 @@ virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev, c= har **path, char **name) =20 ret =3D 0; cleanup: - VIR_FREE(drvlink); if (ret < 0) { VIR_FREE(*path); VIR_FREE(*name); @@ -375,32 +374,27 @@ virPCIDeviceRead32(virPCIDevicePtr dev, int cfgfd, un= signed int pos) static int virPCIDeviceReadClass(virPCIDevicePtr dev, uint16_t *device_class) { - char *path =3D NULL; - char *id_str =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) id_str =3D NULL; unsigned int value; =20 if (!(path =3D virPCIFile(dev->name, "class"))) - return ret; + return -1; =20 /* class string is '0xNNNNNN\n' ... i.e. 9 bytes */ if (virFileReadAll(path, 9, &id_str) < 0) - goto cleanup; + return -1; =20 id_str[8] =3D '\0'; if (virStrToLong_ui(id_str, NULL, 16, &value) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unusual value in %s/devices/%s/class: %s"), PCI_SYSFS, dev->name, id_str); - goto cleanup; + return -1; } =20 *device_class =3D (value >> 8) & 0xFFFF; - ret =3D 0; - cleanup: - VIR_FREE(id_str); - VIR_FREE(path); - return ret; + return 0; } =20 static int @@ -574,7 +568,7 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr de= v, int cfgfd) { uint32_t caps; uint8_t pos; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; int found; =20 /* The PCIe Function Level Reset capability allows @@ -614,7 +608,6 @@ virPCIDeviceDetectFunctionLevelReset(virPCIDevicePtr de= v, int cfgfd) return -1; =20 found =3D virFileExists(path); - VIR_FREE(path); if (found) { VIR_DEBUG("%s %s: buggy device didn't advertise FLR, but is a VF; = forcing flr on", dev->id, dev->name); @@ -926,8 +919,8 @@ virPCIDeviceReset(virPCIDevicePtr dev, virPCIDeviceList *activeDevs, virPCIDeviceList *inactiveDevs) { - char *drvPath =3D NULL; - char *drvName =3D NULL; + VIR_AUTOFREE(char *) drvPath =3D NULL; + VIR_AUTOFREE(char *) drvName =3D NULL; int ret =3D -1; int fd =3D -1; int hdrType =3D -1; @@ -1000,8 +993,6 @@ virPCIDeviceReset(virPCIDevicePtr dev, } =20 cleanup: - VIR_FREE(drvPath); - VIR_FREE(drvName); virPCIDeviceConfigClose(dev, fd); return ret; } @@ -1011,7 +1002,7 @@ static int virPCIProbeStubDriver(virPCIStubDriver driver) { const char *drvname =3D NULL; - char *drvpath =3D NULL; + VIR_AUTOFREE(char *) drvpath =3D NULL; bool probed =3D false; =20 if (driver =3D=3D VIR_PCI_STUB_DRIVER_NONE || @@ -1023,20 +1014,15 @@ virPCIProbeStubDriver(virPCIStubDriver driver) } =20 recheck: - if ((drvpath =3D virPCIDriverDir(drvname)) && virFileExists(drvpath)) { + if ((drvpath =3D virPCIDriverDir(drvname)) && virFileExists(drvpath)) /* driver already loaded, return */ - VIR_FREE(drvpath); return 0; - } - - VIR_FREE(drvpath); =20 if (!probed) { - char *errbuf =3D NULL; + VIR_AUTOFREE(char *) errbuf =3D NULL; probed =3D true; if ((errbuf =3D virKModLoad(drvname, true))) { VIR_WARN("failed to load driver %s: %s", drvname, errbuf); - VIR_FREE(errbuf); goto cleanup; } =20 @@ -1064,38 +1050,30 @@ virPCIProbeStubDriver(virPCIStubDriver driver) int virPCIDeviceUnbind(virPCIDevicePtr dev) { - char *path =3D NULL; - char *drvpath =3D NULL; - char *driver =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) drvpath =3D NULL; + VIR_AUTOFREE(char *) driver =3D NULL; =20 if (virPCIDeviceGetDriverPathAndName(dev, &drvpath, &driver) < 0) - goto cleanup; + return -1; =20 - if (!driver) { + if (!driver) /* The device is not bound to any driver */ - ret =3D 0; - goto cleanup; - } + return 0; =20 if (!(path =3D virPCIFile(dev->name, "driver/unbind"))) - goto cleanup; + return -1; =20 if (virFileExists(path)) { if (virFileWriteStr(path, dev->name, 0) < 0) { virReportSystemError(errno, _("Failed to unbind PCI device '%s' from = %s"), dev->name, driver); - goto cleanup; + return -1; } } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(drvpath); - VIR_FREE(driver); - return ret; + return 0; } =20 =20 @@ -1138,8 +1116,7 @@ static int virPCIDeviceBindWithDriverOverride(virPCIDevicePtr dev, const char *driverName) { - int ret =3D -1; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 if (!(path =3D virPCIFile(dev->name, "driver_override"))) return -1; @@ -1149,26 +1126,22 @@ virPCIDeviceBindWithDriverOverride(virPCIDevicePtr = dev, _("Failed to add driver '%s' to driver_overri= de " " interface of PCI device '%s'"), driverName, dev->name); - goto cleanup; + return -1; } =20 if (virPCIDeviceRebind(dev) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - VIR_FREE(path); - return ret; + return 0; } =20 static int virPCIDeviceUnbindFromStubWithNewid(virPCIDevicePtr dev) { int result =3D -1; - char *drvdir =3D NULL; - char *path =3D NULL; - char *driver =3D NULL; + VIR_AUTOFREE(char *) drvdir =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) driver =3D NULL; =20 /* If the device is currently bound to one of the "well known" * stub drivers, then unbind it, otherwise ignore it. @@ -1257,10 +1230,6 @@ virPCIDeviceUnbindFromStubWithNewid(virPCIDevicePtr = dev) dev->remove_slot =3D false; dev->reprobe =3D false; =20 - VIR_FREE(drvdir); - VIR_FREE(path); - VIR_FREE(driver); - return result; } =20 @@ -1278,8 +1247,7 @@ virPCIDeviceUnbindFromStubWithOverride(virPCIDevicePt= r dev) static int virPCIDeviceUnbindFromStub(virPCIDevicePtr dev) { - int ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 /* * Prefer using the device's driver_override interface, falling back @@ -1289,12 +1257,9 @@ virPCIDeviceUnbindFromStub(virPCIDevicePtr dev) return -1; =20 if (virFileExists(path)) - ret =3D virPCIDeviceUnbindFromStubWithOverride(dev); + return virPCIDeviceUnbindFromStubWithOverride(dev); else - ret =3D virPCIDeviceUnbindFromStubWithNewid(dev); - - VIR_FREE(path); - return ret; + return virPCIDeviceUnbindFromStubWithNewid(dev); } =20 static int @@ -1302,9 +1267,9 @@ virPCIDeviceBindToStubWithNewid(virPCIDevicePtr dev) { int result =3D -1; bool reprobe =3D false; - char *stubDriverPath =3D NULL; - char *driverLink =3D NULL; - char *path =3D NULL; /* reused for different purposes */ + VIR_AUTOFREE(char *) stubDriverPath =3D NULL; + VIR_AUTOFREE(char *) driverLink =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; /* reused for different purposes */ const char *stubDriverName =3D NULL; virErrorPtr err =3D NULL; =20 @@ -1436,10 +1401,6 @@ virPCIDeviceBindToStubWithNewid(virPCIDevicePtr dev) } =20 cleanup: - VIR_FREE(stubDriverPath); - VIR_FREE(driverLink); - VIR_FREE(path); - if (result < 0) virPCIDeviceUnbindFromStub(dev); =20 @@ -1453,10 +1414,9 @@ virPCIDeviceBindToStubWithNewid(virPCIDevicePtr dev) static int virPCIDeviceBindToStubWithOverride(virPCIDevicePtr dev) { - int ret =3D -1; const char *stubDriverName; - char *stubDriverPath =3D NULL; - char *driverLink =3D NULL; + VIR_AUTOFREE(char *) stubDriverPath =3D NULL; + VIR_AUTOFREE(char *) driverLink =3D NULL; =20 /* Check the device is configured to use one of the known stub drivers= */ if (dev->stubDriver =3D=3D VIR_PCI_STUB_DRIVER_NONE) { @@ -1473,35 +1433,28 @@ virPCIDeviceBindToStubWithOverride(virPCIDevicePtr = dev) =20 if (!(stubDriverPath =3D virPCIDriverDir(stubDriverName)) || !(driverLink =3D virPCIFile(dev->name, "driver"))) - goto cleanup; + return -1; =20 if (virFileExists(driverLink)) { if (virFileLinkPointsTo(driverLink, stubDriverPath)) { /* The device is already bound to the correct driver */ VIR_DEBUG("Device %s is already bound to %s", dev->name, stubDriverName); - ret =3D 0; - goto cleanup; + return 0; } } =20 if (virPCIDeviceBindWithDriverOverride(dev, stubDriverName) < 0) - goto cleanup; + return -1; =20 dev->unbind_from_stub =3D true; - ret =3D 0; - - cleanup: - VIR_FREE(stubDriverPath); - VIR_FREE(driverLink); - return ret; + return 0; } =20 static int virPCIDeviceBindToStub(virPCIDevicePtr dev) { - int ret; - char *path; + VIR_AUTOFREE(char *) path =3D NULL; =20 /* * Prefer using the device's driver_override interface, falling back @@ -1511,12 +1464,9 @@ virPCIDeviceBindToStub(virPCIDevicePtr dev) return -1; =20 if (virFileExists(path)) - ret =3D virPCIDeviceBindToStubWithOverride(dev); + return virPCIDeviceBindToStubWithOverride(dev); else - ret =3D virPCIDeviceBindToStubWithNewid(dev); - - VIR_FREE(path); - return ret; + return virPCIDeviceBindToStubWithNewid(dev); } =20 /* virPCIDeviceDetach: @@ -1700,19 +1650,15 @@ virPCIDeviceWaitForCleanup(virPCIDevicePtr dev, con= st char *matcher) static char * virPCIDeviceReadID(virPCIDevicePtr dev, const char *id_name) { - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; char *id_str; =20 if (!(path =3D virPCIFile(dev->name, id_name))) return NULL; =20 /* ID string is '0xNNNN\n' ... i.e. 7 bytes */ - if (virFileReadAll(path, 7, &id_str) < 0) { - VIR_FREE(path); + if (virFileReadAll(path, 7, &id_str) < 0) return NULL; - } - - VIR_FREE(path); =20 /* Check for 0x suffix */ if (id_str[0] !=3D '0' || id_str[1] !=3D 'x') { @@ -1755,8 +1701,8 @@ virPCIDeviceNew(unsigned int domain, unsigned int function) { virPCIDevicePtr dev; - char *vendor =3D NULL; - char *product =3D NULL; + VIR_AUTOFREE(char *) vendor =3D NULL; + VIR_AUTOFREE(char *) product =3D NULL; =20 if (VIR_ALLOC(dev) < 0) return NULL; @@ -1805,15 +1751,11 @@ virPCIDeviceNew(unsigned int domain, =20 VIR_DEBUG("%s %s: initialized", dev->id, dev->name); =20 - cleanup: - VIR_FREE(product); - VIR_FREE(vendor); return dev; =20 error: virPCIDeviceFree(dev); - dev =3D NULL; - goto cleanup; + return NULL; } =20 =20 @@ -2129,8 +2071,7 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, virPCIDeviceFileActor actor, void *opaque) { - char *pcidir =3D NULL; - char *file =3D NULL; + VIR_AUTOFREE(char *) pcidir =3D NULL; DIR *dir =3D NULL; int ret =3D -1; struct dirent *ent; @@ -2145,6 +2086,7 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, goto cleanup; =20 while ((direrr =3D virDirRead(dir, &ent, pcidir)) > 0) { + VIR_AUTOFREE(char *) file =3D NULL; /* Device assignment requires: * $PCIDIR/config, $PCIDIR/resource, $PCIDIR/resourceNNN, * $PCIDIR/rom, $PCIDIR/reset, $PCIDIR/vendor, $PCIDIR/device @@ -2159,8 +2101,6 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, goto cleanup; if ((actor)(dev, file, opaque) < 0) goto cleanup; - - VIR_FREE(file); } } if (direrr < 0) @@ -2170,8 +2110,6 @@ int virPCIDeviceFileIterate(virPCIDevicePtr dev, =20 cleanup: VIR_DIR_CLOSE(dir); - VIR_FREE(file); - VIR_FREE(pcidir); return ret; } =20 @@ -2186,7 +2124,7 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddr= essPtr orig, virPCIDeviceAddressActor actor, void *opaque) { - char *groupPath =3D NULL; + VIR_AUTOFREE(char *) groupPath =3D NULL; DIR *groupDir =3D NULL; int ret =3D -1; struct dirent *ent; @@ -2222,7 +2160,6 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddr= essPtr orig, ret =3D 0; =20 cleanup: - VIR_FREE(groupPath); VIR_DIR_CLOSE(groupDir); return ret; } @@ -2341,28 +2278,25 @@ virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDev= iceAddressPtr devAddr, int virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr) { - char *devName =3D NULL; - char *devPath =3D NULL; - char *groupPath =3D NULL; + VIR_AUTOFREE(char *) devName =3D NULL; + VIR_AUTOFREE(char *) devPath =3D NULL; + VIR_AUTOFREE(char *) groupPath =3D NULL; const char *groupNumStr; unsigned int groupNum; - int ret =3D -1; =20 if (virAsprintf(&devName, "%.4x:%.2x:%.2x.%.1x", addr->domain, addr->bus, addr->slot, addr->function) < 0) - goto cleanup; + return -1; =20 if (!(devPath =3D virPCIFile(devName, "iommu_group"))) - goto cleanup; - if (virFileIsLink(devPath) !=3D 1) { - ret =3D -2; - goto cleanup; - } + return -1; + if (virFileIsLink(devPath) !=3D 1) + return -2; if (virFileResolveLink(devPath, &groupPath) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to resolve device %s iommu_group symlink = %s"), devName, devPath); - goto cleanup; + return -1; } =20 groupNumStr =3D last_component(groupPath); @@ -2371,16 +2305,10 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAdd= ressPtr addr) _("device %s iommu_group symlink %s has " "invalid group number %s"), devName, groupPath, groupNumStr); - ret =3D -1; - goto cleanup; + return -1; } =20 - ret =3D groupNum; - cleanup: - VIR_FREE(devName); - VIR_FREE(devPath); - VIR_FREE(groupPath); - return ret; + return groupNum; } =20 =20 @@ -2390,30 +2318,28 @@ virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAdd= ressPtr addr) char * virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev) { - char *devPath =3D NULL; - char *groupPath =3D NULL; + VIR_AUTOFREE(char *) devPath =3D NULL; + VIR_AUTOFREE(char *) groupPath =3D NULL; char *groupDev =3D NULL; =20 if (!(devPath =3D virPCIFile(dev->name, "iommu_group"))) - goto cleanup; + return NULL; if (virFileIsLink(devPath) !=3D 1) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid device %s iommu_group file %s is not a s= ymlink"), dev->name, devPath); - goto cleanup; + return NULL; } if (virFileResolveLink(devPath, &groupPath) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to resolve device %s iommu_group symlink = %s"), dev->name, devPath); - goto cleanup; + return NULL; } if (virAsprintf(&groupDev, "/dev/vfio/%s", last_component(groupPath)) < 0) - goto cleanup; - cleanup: - VIR_FREE(devPath); - VIR_FREE(groupPath); + return NULL; + return groupDev; } =20 @@ -2614,7 +2540,7 @@ virPCIGetDeviceAddressFromSysfsLink(const char *devic= e_link) { virPCIDeviceAddressPtr bdf =3D NULL; char *config_address =3D NULL; - char *device_path =3D NULL; + VIR_AUTOFREE(char *) device_path =3D NULL; =20 if (!virFileExists(device_link)) { VIR_DEBUG("'%s' does not exist", device_link); @@ -2631,19 +2557,16 @@ virPCIGetDeviceAddressFromSysfsLink(const char *dev= ice_link) =20 config_address =3D last_component(device_path); if (VIR_ALLOC(bdf) < 0) - goto out; + return NULL; =20 if (virPCIDeviceAddressParse(config_address, bdf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to parse PCI config address '%s'"), config_address); VIR_FREE(bdf); - goto out; + return NULL; } =20 - out: - VIR_FREE(device_path); - return bdf; } =20 @@ -2665,7 +2588,7 @@ int virPCIGetPhysicalFunction(const char *vf_sysfs_path, virPCIDeviceAddressPtr *pf) { - char *device_link =3D NULL; + VIR_AUTOFREE(char *) device_link =3D NULL; =20 *pf =3D NULL; =20 @@ -2678,7 +2601,6 @@ virPCIGetPhysicalFunction(const char *vf_sysfs_path, VIR_DEBUG("PF for VF device '%s': %.4x:%.2x:%.2x.%.1x", vf_sysfs_p= ath, (*pf)->domain, (*pf)->bus, (*pf)->slot, (*pf)->function); } - VIR_FREE(device_link); =20 return 0; } @@ -2695,9 +2617,9 @@ virPCIGetVirtualFunctions(const char *sysfs_path, { int ret =3D -1; size_t i; - char *device_link =3D NULL; + VIR_AUTOFREE(char *) totalvfs_file =3D NULL; + VIR_AUTOFREE(char *) totalvfs_str =3D NULL; virPCIDeviceAddressPtr config_addr =3D NULL; - char *totalvfs_file =3D NULL, *totalvfs_str =3D NULL; =20 *virtual_functions =3D NULL; *num_virtual_functions =3D 0; @@ -2719,6 +2641,7 @@ virPCIGetVirtualFunctions(const char *sysfs_path, } =20 do { + VIR_AUTOFREE(char *) device_link =3D NULL; /* look for virtfn%d links until one isn't found */ if (virAsprintf(&device_link, "%s/virtfn%zu", sysfs_path, *num_vir= tual_functions) < 0) goto error; @@ -2736,18 +2659,13 @@ virPCIGetVirtualFunctions(const char *sysfs_path, if (VIR_APPEND_ELEMENT(*virtual_functions, *num_virtual_functions, config_addr) < 0) goto error; - VIR_FREE(device_link); - } while (1); =20 VIR_DEBUG("Found %zu virtual functions for %s", *num_virtual_functions, sysfs_path); ret =3D 0; cleanup: - VIR_FREE(device_link); VIR_FREE(config_addr); - VIR_FREE(totalvfs_file); - VIR_FREE(totalvfs_str); return ret; =20 error: @@ -2765,18 +2683,13 @@ virPCIGetVirtualFunctions(const char *sysfs_path, int virPCIIsVirtualFunction(const char *vf_sysfs_device_link) { - char *vf_sysfs_physfn_link =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) vf_sysfs_physfn_link =3D NULL; =20 if (virAsprintf(&vf_sysfs_physfn_link, "%s/physfn", vf_sysfs_device_link) < 0) - return ret; + return -1; =20 - ret =3D virFileExists(vf_sysfs_physfn_link); - - VIR_FREE(vf_sysfs_physfn_link); - - return ret; + return virFileExists(vf_sysfs_physfn_link); } =20 /* @@ -2868,12 +2781,12 @@ virPCIGetNetName(const char *device_link_sysfs_path, char *physPortID, char **netname) { - char *pcidev_sysfs_net_path =3D NULL; + VIR_AUTOFREE(char *) pcidev_sysfs_net_path =3D NULL; + VIR_AUTOFREE(char *) firstEntryName =3D NULL; + VIR_AUTOFREE(char *) thisPhysPortID =3D NULL; int ret =3D -1; DIR *dir =3D NULL; struct dirent *entry =3D NULL; - char *firstEntryName =3D NULL; - char *thisPhysPortID =3D NULL; size_t i =3D 0; =20 if (virBuildPath(&pcidev_sysfs_net_path, device_link_sysfs_path, @@ -2946,9 +2859,6 @@ virPCIGetNetName(const char *device_link_sysfs_path, } cleanup: VIR_DIR_CLOSE(dir); - VIR_FREE(pcidev_sysfs_net_path); - VIR_FREE(thisPhysPortID); - VIR_FREE(firstEntryName); return ret; } =20 @@ -2959,9 +2869,9 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_dev= ice_path, int *vf_index) { virPCIDeviceAddressPtr pf_config_address =3D NULL; - char *pf_sysfs_device_path =3D NULL; - char *vfname =3D NULL; - char *vfPhysPortID =3D NULL; + VIR_AUTOFREE(char *) pf_sysfs_device_path =3D NULL; + VIR_AUTOFREE(char *) vfname =3D NULL; + VIR_AUTOFREE(char *) vfPhysPortID =3D NULL; int ret =3D -1; =20 if (virPCIGetPhysicalFunction(vf_sysfs_device_path, &pf_config_address= ) < 0) @@ -3016,9 +2926,6 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_dev= ice_path, ret =3D 0; cleanup: VIR_FREE(pf_config_address); - VIR_FREE(pf_sysfs_device_path); - VIR_FREE(vfname); - VIR_FREE(vfPhysPortID); =20 return ret; } @@ -3032,8 +2939,7 @@ virPCIGetMdevTypes(const char *sysfspath, int dirret =3D -1; DIR *dir =3D NULL; struct dirent *entry; - char *types_path =3D NULL; - char *tmppath =3D NULL; + VIR_AUTOFREE(char *) types_path =3D NULL; virMediatedDeviceTypePtr mdev_type =3D NULL; virMediatedDeviceTypePtr *mdev_types =3D NULL; size_t ntypes =3D 0; @@ -3051,6 +2957,7 @@ virPCIGetMdevTypes(const char *sysfspath, } =20 while ((dirret =3D virDirRead(dir, &entry, types_path)) > 0) { + VIR_AUTOFREE(char *) tmppath =3D NULL; /* append the type id to the path and read the attributes from the= re */ if (virAsprintf(&tmppath, "%s/%s", types_path, entry->d_name) < 0) goto cleanup; @@ -3060,8 +2967,6 @@ virPCIGetMdevTypes(const char *sysfspath, =20 if (VIR_APPEND_ELEMENT(mdev_types, ntypes, mdev_type) < 0) goto cleanup; - - VIR_FREE(tmppath); } =20 if (dirret < 0) @@ -3075,8 +2980,6 @@ virPCIGetMdevTypes(const char *sysfspath, for (i =3D 0; i < ntypes; i++) virMediatedDeviceTypeFree(mdev_types[i]); VIR_FREE(mdev_types); - VIR_FREE(types_path); - VIR_FREE(tmppath); VIR_DIR_CLOSE(dir); return ret; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174938034246.10424721982088; Sat, 21 Jul 2018 05:08:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 152D730820DF; Sat, 21 Jul 2018 12:08:53 +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 CB5C3CC400; Sat, 21 Jul 2018 12:08:52 +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 857061841C5A; Sat, 21 Jul 2018 12:08:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8XDd016470 for ; Sat, 21 Jul 2018 08:08:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0EA2B60175; Sat, 21 Jul 2018 12:08:33 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0661760172 for ; Sat, 21 Jul 2018 12:08:28 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2DC536A5C3 for ; Sat, 21 Jul 2018 12:08:16 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id w8-v6so6296048ply.8 for ; Sat, 21 Jul 2018 05:08:16 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=/63wE1mTluF/p9KgWUj4UEn3Zje0QzKLp/j0+mb54Fg=; b=SebDs9Ji4oSVfj706DnkIlqGK0bU+tDosHjvdTh5BVZWLnpJEEYOT57yG+/k1pvLT5 vPE+/2raMv3OF7TkyA5DC2n23WZwCSqDSN6tP2bnN5XTu6a7VIa8z1s07SuS+B8EKFbo 2WdTfIXOIiRlZQ74ZEGv9BbG25rZk5Yr1iJXaN4Ia2bYzS5P0sW/Zs+fwOO5F9HtWP5p akumQEh4+nGCUm7HkS1O7br5uRtDzrjUtYH/vCz80K/Uc7/lUZmYGjQ6nDE2ojMOSY4b uMrkCFQ9MIGOFP1iXZpeKGxwjCOXsR70w6HDys2xMVPMtYHfkiOF1Zf0PD4rbvi11jGr hrRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=/63wE1mTluF/p9KgWUj4UEn3Zje0QzKLp/j0+mb54Fg=; b=gUMZLGWJTdGCQ9oNVEPnCRSvFdeyUc7smamoxMoFxeWbbSOEWL+KW54gHSNKxW0vwL ry5D9ReAZ9JfXpcysoTKS9O2YcFrTQ2V6PydrzES8f6Xiieu2aFiuBpCVQdbCcZWAHFO CPKuKJTFgirriHP3AHIYeMNNVbj9vSfCdW6tG44L9FQzFjwmdwJNgbRWrSijpDCPn46u k9O0feiUwpHz4giEMpIaiWvjaKShAczZ9AFG6HDJ9SynQLEH48/DfywActkdPG0Wz5rx zJO2ozGUqMJYPGQnGMdzxp4EbW6W/tA0jp8y8ny2LboXIzk5o3LlzUjKXN9vxT636aSp 16IA== X-Gm-Message-State: AOUpUlE6DGDxpO6btHJ2XgI1DeEtPqJgVeW7dhdbVDOt2OPuQFfMg59d R5RAknAvim0fsxyzwZNvROPRQ1ax X-Google-Smtp-Source: AAOMgpd7PJ0JGrm2oDhJnS8gDJ3eh4NbJ4uRXSQjefeNrPCpU3bD3QhAPKhI8jbpsqgWGm1Avw/q3A== X-Received: by 2002:a17:902:262:: with SMTP id 89-v6mr5597478plc.221.1532174896219; Sat, 21 Jul 2018 05:08:16 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:53 +0530 Message-Id: <1532174832-21644-22-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 21 Jul 2018 12:08:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 21 Jul 2018 12:08:17 +0000 (UTC) for IP:'209.85.160.68' DOMAIN:'mail-pl0-f68.google.com' HELO:'mail-pl0-f68.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 21/40] util: pci: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 21 Jul 2018 12:08:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virpci.c | 51 ++++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 1f6ac0b..7b0964c 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -490,8 +490,6 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predi= cate, ret =3D 1; break; } - - virPCIDeviceFree(check); } VIR_DIR_CLOSE(dir); return ret; @@ -781,7 +779,8 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev, int cfgfd, virPCIDeviceList *inactiveDevs) { - virPCIDevicePtr parent, conflict; + VIR_AUTOPTR(virPCIDevice) parent =3D NULL; + VIR_AUTOPTR(virPCIDevice) conflict =3D NULL; uint8_t config_space[PCI_CONF_LEN]; uint16_t ctl; int ret =3D -1; @@ -795,7 +794,6 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev, virReportError(VIR_ERR_INTERNAL_ERROR, _("Active %s devices on bus with %s, not doing bus = reset"), conflict->name, dev->name); - virPCIDeviceFree(conflict); return -1; } =20 @@ -848,7 +846,6 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev, =20 out: virPCIDeviceConfigClose(parent, parentfd); - virPCIDeviceFree(parent); return ret; } =20 @@ -1270,8 +1267,8 @@ virPCIDeviceBindToStubWithNewid(virPCIDevicePtr dev) VIR_AUTOFREE(char *) stubDriverPath =3D NULL; VIR_AUTOFREE(char *) driverLink =3D NULL; VIR_AUTOFREE(char *) path =3D NULL; /* reused for different purposes */ + VIR_AUTOPTR(virError) err =3D NULL; const char *stubDriverName =3D NULL; - virErrorPtr err =3D NULL; =20 /* Check the device is configured to use one of the known stub drivers= */ if (dev->stubDriver =3D=3D VIR_PCI_STUB_DRIVER_NONE) { @@ -1406,7 +1403,6 @@ virPCIDeviceBindToStubWithNewid(virPCIDevicePtr dev) =20 if (err) virSetError(err); - virFreeError(err); =20 return result; } @@ -1679,19 +1675,16 @@ virPCIGetAddrString(unsigned int domain, unsigned int function, char **pciConfigAddr) { - virPCIDevicePtr dev =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virPCIDevice) dev =3D NULL; =20 dev =3D virPCIDeviceNew(domain, bus, slot, function); if (dev !=3D NULL) { if (VIR_STRDUP(*pciConfigAddr, dev->name) < 0) - goto cleanup; - ret =3D 0; + return -1; + return 0; } =20 - cleanup: - virPCIDeviceFree(dev); - return ret; + return -1; } =20 virPCIDevicePtr @@ -1962,10 +1955,10 @@ virPCIDeviceListAddCopy(virPCIDeviceListPtr list, v= irPCIDevicePtr dev) =20 if (!copy) return -1; - if (virPCIDeviceListAdd(list, copy) < 0) { - virPCIDeviceFree(copy); + if (virPCIDeviceListAdd(list, copy) < 0) return -1; - } + + copy =3D NULL; return 0; } =20 @@ -2013,8 +2006,7 @@ void virPCIDeviceListDel(virPCIDeviceListPtr list, virPCIDevicePtr dev) { - virPCIDevicePtr ret =3D virPCIDeviceListSteal(list, dev); - virPCIDeviceFree(ret); + VIR_AUTOPTR(virPCIDevice) ret =3D virPCIDeviceListSteal(list, dev); } =20 int @@ -2168,22 +2160,18 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAd= dressPtr orig, static int virPCIDeviceGetIOMMUGroupAddOne(virPCIDeviceAddressPtr newDevAddr, void *o= paque) { - int ret =3D -1; virPCIDeviceListPtr groupList =3D opaque; - virPCIDevicePtr newDev; + VIR_AUTOPTR(virPCIDevice) newDev =3D NULL; =20 if (!(newDev =3D virPCIDeviceNew(newDevAddr->domain, newDevAddr->bus, newDevAddr->slot, newDevAddr->function)= )) - goto cleanup; + return -1; =20 if (virPCIDeviceListAdd(groupList, newDev) < 0) - goto cleanup; + return -1; =20 newDev =3D NULL; /* it's now on the list */ - ret =3D 0; - cleanup: - virPCIDeviceFree(newDev); - return ret; + return 0; } =20 =20 @@ -2395,7 +2383,7 @@ virPCIDeviceDownstreamLacksACS(virPCIDevicePtr dev) static int virPCIDeviceIsBehindSwitchLackingACS(virPCIDevicePtr dev) { - virPCIDevicePtr parent; + VIR_AUTOPTR(virPCIDevice) parent =3D NULL; =20 if (virPCIDeviceGetParent(dev, &parent) < 0) return -1; @@ -2419,14 +2407,13 @@ virPCIDeviceIsBehindSwitchLackingACS(virPCIDevicePt= r dev) * parent can be found */ do { - virPCIDevicePtr tmp; + VIR_AUTOPTR(virPCIDevice) tmp =3D NULL; int acs; int ret; =20 acs =3D virPCIDeviceDownstreamLacksACS(parent); =20 if (acs) { - virPCIDeviceFree(parent); if (acs < 0) return -1; else @@ -2435,7 +2422,6 @@ virPCIDeviceIsBehindSwitchLackingACS(virPCIDevicePtr = dev) =20 tmp =3D parent; ret =3D virPCIDeviceGetParent(parent, &parent); - virPCIDeviceFree(tmp); if (ret < 0) return -1; } while (parent); @@ -2940,7 +2926,7 @@ virPCIGetMdevTypes(const char *sysfspath, DIR *dir =3D NULL; struct dirent *entry; VIR_AUTOFREE(char *) types_path =3D NULL; - virMediatedDeviceTypePtr mdev_type =3D NULL; + VIR_AUTOPTR(virMediatedDeviceType) mdev_type =3D NULL; virMediatedDeviceTypePtr *mdev_types =3D NULL; size_t ntypes =3D 0; size_t i; @@ -2976,7 +2962,6 @@ virPCIGetMdevTypes(const char *sysfspath, ret =3D ntypes; ntypes =3D 0; cleanup: - virMediatedDeviceTypeFree(mdev_type); for (i =3D 0; i < ntypes; i++) virMediatedDeviceTypeFree(mdev_types[i]); VIR_FREE(mdev_types); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175031659955.2309511818175; Sat, 21 Jul 2018 05:10:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 512DE8110B; Sat, 21 Jul 2018 12:10:24 +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 20977300165E; Sat, 21 Jul 2018 12:10:24 +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 C69154EE10; Sat, 21 Jul 2018 12:10:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8ZTP016484 for ; Sat, 21 Jul 2018 08:08:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id AAF5C608F7; Sat, 21 Jul 2018 12:08:35 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9F723608F2 for ; Sat, 21 Jul 2018 12:08:30 +0000 (UTC) Received: from mail-pl0-f66.google.com (mail-pl0-f66.google.com [209.85.160.66]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 730823082A2E for ; Sat, 21 Jul 2018 12:08:19 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id m1-v6so1307839plt.6 for ; Sat, 21 Jul 2018 05:08:19 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=agybgkDLoFNm7SHAOmTtW5J+cnNnqnu/j7pnze7enoY=; b=dELWk4iWzKxQaTjOroNcyyLhDa31Py1+an1i3m7wTsDNTKqVT8Azu9vsbYLF/BuUJx 0X0/e4zlOdC22kGqtWAyNHDvpiFLs19TsWRlMlrLxOmAL5n+xv7GXr4075HuKmUxy0TN XIc5UYtLIc74AxTVS6nL84t8IbOLPquIIRQjpFPl5nqVOHvzLBDTwB6AkPhcqHXjKpHw wu/cMTU/z63L8+sNeYh2fChmMdFWWNNW7vZ3sLXhOBPzS9XvzOluhBnJY9gAV8hLSO5o JBfKtrv5nHTrXZG6lQPNcl6g9QNkrTds6AAYBO+/zGqQENGPooMxrgg+2y5SM7kREPV3 HWoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=agybgkDLoFNm7SHAOmTtW5J+cnNnqnu/j7pnze7enoY=; b=mi4pgolYK4w2aPeyCblPwfR1LQ0BkqztUoorTN5akTvSvEH9tVJRVEpVF0lbDcgVC7 ttqL6MLEDTXNu5cpkbDYfCy/g4dwxp5cKkixz3tJxSFz2K4yYim3Mnk3AlXTivV1icNM mVfmtszQULI4S6U7HXnXi1qe3gLUMYpVvS/bBb9E+5gNdiFd8hA5NGMCo5Z4ZMVDhUFY BVyM+bIM5qTMJrNFJ2eKluOGQUeF+4LmASTPpqqMziqO1nTIg5WMWLGo/4NW9DWaEjy/ /FY5h4KLe73CyfJamsUXIodHtnVvFcZ44llL7EWhxXMiBBySPdSOohEk/6aPy4ify/eF TlTw== X-Gm-Message-State: AOUpUlH4jftswLurxwmjlfccFlivFrdtDMzIfFW1nMYj5MQVpLf5NECu CIEWRkf9ik+ekZRisdx1lPU/LAlK X-Google-Smtp-Source: AAOMgpfvNk3IxX0zcTUUi7ZEq4SqWPk99p5w8YR+YJK3iJHuIkeb8kodZ0gbIZM2lY9q8usM+qtjKw== X-Received: by 2002:a17:902:599b:: with SMTP id p27-v6mr5575040pli.191.1532174898692; Sat, 21 Jul 2018 05:08:18 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:54 +0530 Message-Id: <1532174832-21644-23-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 21 Jul 2018 12:08:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 21 Jul 2018 12:08:19 +0000 (UTC) for IP:'209.85.160.66' DOMAIN:'mail-pl0-f66.google.com' HELO:'mail-pl0-f66.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.66 mail-pl0-f66.google.com 209.85.160.66 mail-pl0-f66.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 22/40] util: netdevvlan: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 21 Jul 2018 12:10:30 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virNetDevVlanPtr is declared using VIR_AUTOPTR, the function virNetDevVlanFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virnetdevvlan.c | 1 - src/util/virnetdevvlan.h | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/virnetdevvlan.c b/src/util/virnetdevvlan.c index 4c8bce5..0afc47b 100644 --- a/src/util/virnetdevvlan.c +++ b/src/util/virnetdevvlan.c @@ -24,7 +24,6 @@ #include "internal.h" #include "virerror.h" #include "virnetdevvlan.h" -#include "viralloc.h" =20 #define VIR_FROM_THIS VIR_FROM_NONE =20 diff --git a/src/util/virnetdevvlan.h b/src/util/virnetdevvlan.h index 7f63626..be85f59 100644 --- a/src/util/virnetdevvlan.h +++ b/src/util/virnetdevvlan.h @@ -23,6 +23,8 @@ =20 # include =20 +# include "viralloc.h" + typedef enum { VIR_NATIVE_VLAN_MODE_DEFAULT =3D 0, VIR_NATIVE_VLAN_MODE_TAGGED, @@ -48,4 +50,6 @@ void virNetDevVlanFree(virNetDevVlanPtr vlan); int virNetDevVlanEqual(const virNetDevVlan *a, const virNetDevVlan *b); int virNetDevVlanCopy(virNetDevVlanPtr dst, const virNetDevVlan *src); =20 +VIR_DEFINE_AUTOPTR_FUNC(virNetDevVlan, virNetDevVlanFree) + #endif /* __VIR_NETDEV_VLAN_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175049061116.93190562891095; Sat, 21 Jul 2018 05:10:49 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 69B9C83F3E; Sat, 21 Jul 2018 12:10:46 +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 3261510694C3; Sat, 21 Jul 2018 12:10:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BFBDB4EE1F; Sat, 21 Jul 2018 12:10:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8ZLF016489 for ; Sat, 21 Jul 2018 08:08:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id D8A015D9CD; Sat, 21 Jul 2018 12:08:35 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D156A5D9CC for ; Sat, 21 Jul 2018 12:08:33 +0000 (UTC) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 08376C057FA1 for ; Sat, 21 Jul 2018 12:08:22 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id k3-v6so8967471pgq.5 for ; Sat, 21 Jul 2018 05:08:22 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=GMyjK4OtyFa7bpkM8zTeIxli61EMqpt2Fm29PmUyIVs=; b=g33rW6dQaqtZTcQ9zHetCzhJz0EINTcAJOULMRnh7OY4anvNvxjsxl2gTK866CBs02 22Dm0SNlWhOXePgdTMNY2Gd1bl2CzBVA/EFhXt14nNAQsm9xj5SSqVVkMKamDIXwnSlU 9Nl76AvVFWU0y5n81GKksVvqOt21ML55OrmYOcTDPOLZfqGlMr4G2QWwSM1ZXKi1reLK 1K0wTrdKnok3vyfyTO9DmvUIQSlxWl2vzuRneXf7remLw/wcd6GjvnyJPJSJjsqDG8ac Y5XiA+yjqWn2LIEs8r/JnNupH+74EXYnJx484ul/MZs+3dM3LD5ha6K5akEMVkAweYds 7sDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=GMyjK4OtyFa7bpkM8zTeIxli61EMqpt2Fm29PmUyIVs=; b=P3xzlI6sz1zzkKSy42LHEhXXDmjNBt94HhTjmLuSWdH748XJwETYiWLabpYcZiBPrU 1FIl21X8pkANtQ0JsBrbAsU3l4G4PtM07amfDZCpcm0WGCh9CJcSUTIbMSjwseEq+MYZ JOJJi5eX/gR/e1CYPJcVM/tBzPYmsf9yuAh0d4F/Aen4kWGSHSYaYNDDxr9FYlVxnEiC J4SP+iYyrseP67mfgHnO7PJknTF9y4q6tzbi9RPpROSY6u34sB7PDwePtD4/fOQ482L1 gprfiJRMoNook1GZ6nVTVqebTGTti+PCxDd9ZXHwd0Yk+Q5QvLx7PNYo6NKelVbG/0FH D9xw== X-Gm-Message-State: AOUpUlHVhCfzE62DBFB0vuT1uboZle2IL6T+S7oFhPxgn0XO35BkS+b8 WWUIEb9KBTqbITR0RNCRVWELowT/ X-Google-Smtp-Source: AAOMgpeo/va8WsMxtYydIUJ8TPKO2XHaTKuAwPVmkQShSsUtcK3EdThFCEDsO+bAiINgfQMurWzRHQ== X-Received: by 2002:a62:b612:: with SMTP id j18-v6mr5877453pff.199.1532174901330; Sat, 21 Jul 2018 05:08:21 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:55 +0530 Message-Id: <1532174832-21644-24-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:08:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:08:22 +0000 (UTC) for IP:'209.85.215.170' DOMAIN:'mail-pg1-f170.google.com' HELO:'mail-pg1-f170.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.170 mail-pg1-f170.google.com 209.85.215.170 mail-pg1-f170.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 23/40] util: usb: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 21 Jul 2018 12:10:48 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virUSBDevicePtr is declared using VIR_AUTOPTR, the function virUSBDeviceFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virusb.c | 1 - src/util/virusb.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/virusb.c b/src/util/virusb.c index 2fe1bfc..0a8dd0d 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -35,7 +35,6 @@ =20 #include "virusb.h" #include "virlog.h" -#include "viralloc.h" #include "virutil.h" #include "virerror.h" #include "virfile.h" diff --git a/src/util/virusb.h b/src/util/virusb.h index 716e8c6..5cb9faa 100644 --- a/src/util/virusb.h +++ b/src/util/virusb.h @@ -27,6 +27,7 @@ =20 # include "internal.h" # include "virobject.h" +# include "viralloc.h" =20 # define USB_DEVFS "/dev/bus/usb/" =20 @@ -99,4 +100,6 @@ void virUSBDeviceListDel(virUSBDeviceListPtr list, virUSBDevicePtr virUSBDeviceListFind(virUSBDeviceListPtr list, virUSBDevicePtr dev); =20 +VIR_DEFINE_AUTOPTR_FUNC(virUSBDevice, virUSBDeviceFree) + #endif /* __VIR_USB_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175127698113.94358694288314; Sat, 21 Jul 2018 05:12:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 857713082A4B; Sat, 21 Jul 2018 12:12:01 +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 538305D9CB; Sat, 21 Jul 2018 12:12:00 +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 0A9181841C5A; Sat, 21 Jul 2018 12:12:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8ZBb016490 for ; Sat, 21 Jul 2018 08:08:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB83F5D9CC; Sat, 21 Jul 2018 12:08:35 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D080A5D9CB for ; Sat, 21 Jul 2018 12:08:35 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57065356D6 for ; Sat, 21 Jul 2018 12:08:24 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id n7-v6so8961186pgq.4 for ; Sat, 21 Jul 2018 05:08:24 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=WgQE8YlFwKO8HXIzMD8rDG5RdRhCUcYIpz+Ud9qf/U0=; b=U/W0gcM22VteNL+IY0FSX9h91GedtY1VUsDI1SqY807Mx6upx6FqRUKfEXKvxzRzIj vbJlFVfJ3ycUg6PXkT8LysHv3A8eOsBkmNX5Ya9g7/OQM57PWWkNeoBgYmBsvzo7/xmp rRNvLDga9jjmqEpJVMKTsDZKXMJpG77qLfpDi3sS1Jqf6s9OEbPLdXEtSxQsRRDgy7r6 yECZA3Ksia+drwEiewz9T9/KP5FHnzPlm3NjgqZWJnrDeZBwYPTSCRecZXRcW/kAdn9J q2PCu8JUk5uxDzhF4C06s8fsuqsnrC77ultioV3SlPi8IvoM1LKCa8vTeXDPm0xbPT9L HsPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=WgQE8YlFwKO8HXIzMD8rDG5RdRhCUcYIpz+Ud9qf/U0=; b=bJaPiwrwz0yOVDpLxdTqudyHjOdI+21pcYeJt70KakXpONXNDOw//t3kLEjCBENPb6 dx5hjB6ouC4Yda/qlmrlfGuFRG5I1p+dri2lbjbzFcxhuXPxINYO6HjgmifjYvHTBRsZ tRpdzYorXhZ5g7/KcDslS+4D9Z5TZKNnKVSzuqorjV6pHWBPSaw74tZwLW8QdDdjN8gI es0q7nQhI9r2TwMn8dVYWuvaElgM69R8fpQwD1LN58xdTvYtej8QeDyUTvwCfNF1DSEA UEWvOXjJm3NH32Zs7EtWsW1T42dUSbEOo5SPRoxgj8sU2H4XNGQjKWxUtAS0w6m9/l+G 7uRQ== X-Gm-Message-State: AOUpUlGzH9Gx3G1ahHh62DWTMhF3c6BupRvkxZx18BZ8u9C3Sc4S1mmY IBfCmAJsCaMun0FGs7THv0mmi4GX X-Google-Smtp-Source: AAOMgpfEpcQzK2fKnaSDadE4eKBDDm9Gl8K8EgK1ubCKSdnTJ0BfxKJVmurHjxj3aQcvQfYjKR3uDw== X-Received: by 2002:a62:748:: with SMTP id b69-v6mr5827151pfd.177.1532174903607; Sat, 21 Jul 2018 05:08:23 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:56 +0530 Message-Id: <1532174832-21644-25-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 21 Jul 2018 12:08:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 21 Jul 2018 12:08:24 +0000 (UTC) for IP:'209.85.215.196' DOMAIN:'mail-pg1-f196.google.com' HELO:'mail-pg1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 24/40] util: usb: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 21 Jul 2018 12:12:07 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virusb.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/util/virusb.c b/src/util/virusb.c index 0a8dd0d..c14683f 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -90,29 +90,25 @@ VIR_ONCE_GLOBAL_INIT(virUSB) static int virUSBSysReadFile(const char *f_name, const char *d_name, int base, unsigned int *value) { - int ret =3D -1, tmp; - char *buf =3D NULL; - char *filename =3D NULL; + int tmp; + VIR_AUTOFREE(char *) buf =3D NULL; + VIR_AUTOFREE(char *) filename =3D NULL; char *ignore =3D NULL; =20 tmp =3D virAsprintf(&filename, USB_SYSFS "/devices/%s/%s", d_name, f_n= ame); if (tmp < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(filename, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if (virStrToLong_ui(buf, &ignore, base, value) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not parse usb file %s"), filename); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(filename); - VIR_FREE(buf); - return ret; + return 0; } =20 static virUSBDeviceListPtr --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174953866633.3873089573002; Sat, 21 Jul 2018 05:09:13 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E3AE356FC; Sat, 21 Jul 2018 12:09:12 +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 54F79308BDAD; Sat, 21 Jul 2018 12:09:12 +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 094DA1841C57; Sat, 21 Jul 2018 12:09:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8fO1016534 for ; Sat, 21 Jul 2018 08:08:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 54913C4A64; Sat, 21 Jul 2018 12:08:41 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C035CC106 for ; Sat, 21 Jul 2018 12:08:37 +0000 (UTC) Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C7E1F87628 for ; Sat, 21 Jul 2018 12:08:26 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id p23-v6so8961808pgv.13 for ; Sat, 21 Jul 2018 05:08:26 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=m8/2IYuVFOBpfouYegF7ooIJ2cEy+2rDeoKW1D0X3zQ=; b=sWIl/8zL5q9sKlyGZ0u1Fz7Q/e0ExALpceEMd+tED/z0A6J+kb/t/1kWsXMybuGnFx 7wVMua+ULlObTLL19vaKOqHMcmcNWdtVbBNvhOgito7Q8z1ns7mgA+CBwPC25G1Vqdjv I1YWz4hpmHv73AJy+PnnRd0s6G6vjY591sR08ZAJ+EJ7iaxDaw1rfyovgasFtd7XA6aX G6EthQ+XCi+Hl89S6uatM1lKZs473Kxfs3rRMB6htIEQtJXIXLkzbwB/hxNOT7isX8e3 JfGVuQfacUwQwAdaFur1G/SzJFZD7VFIhuLCIAC46PuQ9qLksvg4zCcl6gLCjYubbddm 5wjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=m8/2IYuVFOBpfouYegF7ooIJ2cEy+2rDeoKW1D0X3zQ=; b=AOI1OWGkDhQtWDoJqEhL+enaGXe7hAG1IK/Fxtwb4LOYMOP71dXHjWPndS+qvH+wae VFAYWjPpNE7frnbalpaltM55OJNbPDX94Gi8hLEY7IrOWONNDTqMXRW/tlkxrAi2Sidq z5IQegXortHQcxjHK5fnc1gRxVLCi533a35b3hAHJSg6eMqQisT8mLcOWgsJz43yuVP1 CWHvmc+98dld/JS88dMgplZ+Uh2R/wpoKXj5K5/kLyFIl61xRswwfNIDWq7S4BYs5SNM 5YSShuyAq7l/L5r9a9Svz3Yz1v/XWKJySGsbmFA0X46xxIhR2EkllKU+d9w9sTzIQxJR +7bw== X-Gm-Message-State: AOUpUlE8bE7NN2SPxP8Hi/YyVJO5hfCzr9UZwcs7XP24laZ7Kh9jRlMc MmhNEUsOWqXeix2i8kR3IaF1Tfvz X-Google-Smtp-Source: AAOMgpeAmqv81NJ20drrD05p0BFRGZdKe/JuWGrQ631EmgwJYpV4C5B53qbvoaX1Ric4tHmIAnuLUg== X-Received: by 2002:a63:4506:: with SMTP id s6-v6mr5609483pga.422.1532174906127; Sat, 21 Jul 2018 05:08:26 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:57 +0530 Message-Id: <1532174832-21644-26-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:08:26 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:08:26 +0000 (UTC) for IP:'209.85.215.196' DOMAIN:'mail-pg1-f196.google.com' HELO:'mail-pg1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.196 mail-pg1-f196.google.com 209.85.215.196 mail-pg1-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 25/40] util: usb: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 21 Jul 2018 12:09:13 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virusb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/virusb.c b/src/util/virusb.c index c14683f..cfeac51 100644 --- a/src/util/virusb.c +++ b/src/util/virusb.c @@ -508,8 +508,7 @@ void virUSBDeviceListDel(virUSBDeviceListPtr list, virUSBDevicePtr dev) { - virUSBDevicePtr ret =3D virUSBDeviceListSteal(list, dev); - virUSBDeviceFree(ret); + VIR_AUTOPTR(virUSBDevice) ret =3D virUSBDeviceListSteal(list, dev); } =20 virUSBDevicePtr --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15321750720621023.5349303902746; Sat, 21 Jul 2018 05:11:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB09581DFE; Sat, 21 Jul 2018 12:11:10 +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 7942ACC10A; Sat, 21 Jul 2018 12:11:09 +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 354104EE0F; Sat, 21 Jul 2018 12:11:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8kdb016555 for ; Sat, 21 Jul 2018 08:08:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0BAC15B682; Sat, 21 Jul 2018 12:08:46 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEC815B683 for ; Sat, 21 Jul 2018 12:08:40 +0000 (UTC) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 38AB583F4C for ; Sat, 21 Jul 2018 12:08:29 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id y4-v6so8960774pgp.9 for ; Sat, 21 Jul 2018 05:08:29 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=RCrvIqp1byacM1QMTfFR4iqIhteF/YmK3rnBe8ZZP4w=; b=s8qO/JE0E8H+Ypo5A0t6RrjiXl+Cq4N4xUkkWHVjZyvi00ZWL2Vrg3AbJ10wlqtxBg C6gIOomFp7lLXIovtTrT5gSe4S94NKMzfNUwZeqKBmOPhQFBNvuKmffMv9h9uz2VnQcn gUDUvRKO1uxqhxdQLu7R/5ZTKx6B2TxTTSJqDoVMSSkwJ93DQZk7iFHvbmYufu1FbPhw ri4fujHma6AZYQE6978htg7/w1he06iutOW9qXqBUeOdOV1SoKhF3sfzK3kP385uUMFw uSo+eo+azuEAI7lCTp8gHuZJDGQ1x1Iz46tnCdPZzv2XA7RVHeoZHbj0NuN7204AZsZR IDxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=RCrvIqp1byacM1QMTfFR4iqIhteF/YmK3rnBe8ZZP4w=; b=nw7q4lhknkWemOo23Ja51dEGFZdLKoug5ZtnvYp0JAQe53VRJyDE6nMKYqRtcBnpdp jbIBmvhkomc3FpoDSYV1Qz/912ATJkp/ra8kbn+aXJKpGo2bG8fmTlFj17cq8ZBps19s W3Xzm15GIis7809zBca3VCJzMzU/WdLerzKlDsMJozPEczDqydlVZ+MmbP0sVkiWBWAD ef/PW2RM+G6QODV+pcfG4a2nFzGCXmB6aCPYmkuGyMMDUF811+1p81Gf7d4E9jxEkRyF JcTF8Ym8NwL26Y0o3droMRETMbksrII+ipc7Fz4rNUKqfMrYBWt4Wtje2nC7Aq8w6pTf gbXA== X-Gm-Message-State: AOUpUlGBOcyct8mKWNgTHrV/4N0f8fa3WEeOolcNVcXravWNnKlsuBwr iIib+uFa19QcgTr/s8Or1ejxH/MM X-Google-Smtp-Source: AAOMgpdYFEWeic72RLDNr+4FCVD99aONJD7yX/vq8TVEc1jeHy7/kadmPV3jL/WAOUPKcFq6lKNhkg== X-Received: by 2002:a63:121a:: with SMTP id h26-v6mr5564413pgl.316.1532174908512; Sat, 21 Jul 2018 05:08:28 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:58 +0530 Message-Id: <1532174832-21644-27-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 21 Jul 2018 12:08:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 21 Jul 2018 12:08:29 +0000 (UTC) for IP:'209.85.215.171' DOMAIN:'mail-pg1-f171.google.com' HELO:'mail-pg1-f171.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.215.171 mail-pg1-f171.google.com 209.85.215.171 mail-pg1-f171.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 26/40] util: scsi: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 21 Jul 2018 12:11:11 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When variables of type virSCSIDevicePtr and virUsedByInfoPtr are declared using VIR_AUTOPTR, the functions virSCSIDeviceFree and virSCSIDeviceUsedByInfoFree, respectively, will be run automatically on them when they go out of scope. This commit also adds an intermediate typedef for virCgroup type for use with the cleanup macros by renaming the struct in src/util/vircgrouppriv.h from virCgroup to _virCgroup. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virscsi.c | 5 +++-- src/util/virscsi.h | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/util/virscsi.c b/src/util/virscsi.c index b51103a..33292f6 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -37,7 +37,6 @@ =20 #include "virlog.h" #include "virscsi.h" -#include "viralloc.h" #include "virfile.h" #include "virutil.h" #include "virstring.h" @@ -54,7 +53,8 @@ struct _virUsedByInfo { char *drvname; /* which driver */ char *domname; /* which domain */ }; -typedef struct _virUsedByInfo *virUsedByInfoPtr; +typedef struct _virUsedByInfo virUsedByInfo; +typedef virUsedByInfo *virUsedByInfoPtr; =20 struct _virSCSIDevice { unsigned int adapter; @@ -264,6 +264,7 @@ virSCSIDeviceUsedByInfoFree(virUsedByInfoPtr used_by) VIR_FREE(used_by->domname); VIR_FREE(used_by); } +VIR_DEFINE_AUTOPTR_FUNC(virUsedByInfo, virSCSIDeviceUsedByInfoFree) =20 void virSCSIDeviceFree(virSCSIDevicePtr dev) diff --git a/src/util/virscsi.h b/src/util/virscsi.h index 9f8b3ec..b96d862 100644 --- a/src/util/virscsi.h +++ b/src/util/virscsi.h @@ -26,6 +26,7 @@ =20 # include "internal.h" # include "virobject.h" +# include "viralloc.h" =20 typedef struct _virSCSIDevice virSCSIDevice; typedef virSCSIDevice *virSCSIDevicePtr; @@ -95,4 +96,6 @@ void virSCSIDeviceListDel(virSCSIDeviceListPtr list, virSCSIDevicePtr virSCSIDeviceListFind(virSCSIDeviceListPtr list, virSCSIDevicePtr dev); =20 +VIR_DEFINE_AUTOPTR_FUNC(virSCSIDevice, virSCSIDeviceFree) + #endif /* __VIR_SCSI_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174983298324.6501186946433; Sat, 21 Jul 2018 05:09:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 262A230E686B; Sat, 21 Jul 2018 12:09:37 +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 E63662016206; Sat, 21 Jul 2018 12:09:35 +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 A27384EE0B; Sat, 21 Jul 2018 12:09:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8hLx016542 for ; Sat, 21 Jul 2018 08:08:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 90CDD600C7; Sat, 21 Jul 2018 12:08:43 +0000 (UTC) Received: from mx1.redhat.com (ext-mx12.extmail.prod.ext.phx2.redhat.com [10.5.110.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8467B600C4 for ; Sat, 21 Jul 2018 12:08:43 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 78748308A943 for ; Sat, 21 Jul 2018 12:08:32 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id s7-v6so5535413pgv.3 for ; Sat, 21 Jul 2018 05:08:32 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.29 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=AwcQfhJEKRZOlhi+TvAwaC2eCIxdR4pQnw6bvxjf5mg=; b=KWjtq2nC/thr8GwQimDVg8+xFqwFYY/g7WnwzCx8sz2KtCYIbRMLjxQNTn5o0QAgXY djwU9xh74fdoSPaVK+Jzb9xZXAv+lE2bH7zFKbl51YjdNDoFoXJfGA8q5JCEYHTYBLxd t3e2qxoL+MsEKXY2Vm9Z1Rueqyrt/hswPnKGIH0BZUgxdorK3tC/Sz40kjhshhEf6s6r BjbofauRk8kymG5xv68MwAjjc1+oDF4yXG+m1WBfa5cNPDUSF4dxGzLvHKC4sjjzwtFw DelsDQQdwOcvnQy4qFYf6IU7SRL+hFLzWSLz3zs2zV/vfeIb3IwRYhL6Pa/cKbRo/GCg NQgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=AwcQfhJEKRZOlhi+TvAwaC2eCIxdR4pQnw6bvxjf5mg=; b=Mjoenw5gS87dv1wkDQvyUdyioaahbIF69bc/QKfeRKiX6nHbQxnFmsfMAQW0c/fXoI AQUBWYbGqRg4zkBHAgA9rfYo9bsdnkjdq6fJcci30BLdGp5hLWkqxgrni978i1TWIgZS Il7dctiHgyskldYuy9io09Ynb8RPF4/OjEFKlXJyOMid6/1hUxm++1/YatTG+Jj30rav cU24soEqfg0PmIJJebMlalyimq7bEW3rm0ymq2wd0Vl02pxodt5SFSM7sModFI2Qj4GN EFIYP4nmfKUJB0w1uDOhBZPHbMhiQ+2hWs2NxB3KpRZ2NI23IpgDJXeUahdInpr5sOcX yeog== X-Gm-Message-State: AOUpUlG/oM2SlhsemXUL/GZkpTvnTnl+obMhxr/llEpeLmgPTsXvc3GG 3e2wyO/ZfB7exqNwgk0XCVHARPmC X-Google-Smtp-Source: AAOMgpcxR8Zq0orCW1BOisP2XNPPtnrPduGKPAQp9BqhMFzRRkeQihS6VW91wd3K9CZeuU+a7uamhA== X-Received: by 2002:a63:2803:: with SMTP id o3-v6mr5525907pgo.158.1532174911779; Sat, 21 Jul 2018 05:08:31 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:59 +0530 Message-Id: <1532174832-21644-28-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sat, 21 Jul 2018 12:08:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Sat, 21 Jul 2018 12:08:32 +0000 (UTC) for IP:'209.85.215.194' DOMAIN:'mail-pg1-f194.google.com' HELO:'mail-pg1-f194.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.194 mail-pg1-f194.google.com 209.85.215.194 mail-pg1-f194.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.41 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 27/40] util: scsi: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 21 Jul 2018 12:09:42 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virscsi.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/util/virscsi.c b/src/util/virscsi.c index 33292f6..ba0a688 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -115,7 +115,7 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix, { DIR *dir =3D NULL; struct dirent *entry; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; char *sg =3D NULL; unsigned int adapter_id; const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICE= S; @@ -139,7 +139,6 @@ virSCSIDeviceGetSgName(const char *sysfs_prefix, =20 cleanup: VIR_DIR_CLOSE(dir); - VIR_FREE(path); return sg; } =20 @@ -155,7 +154,7 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix, { DIR *dir =3D NULL; struct dirent *entry; - char *path =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; char *name =3D NULL; unsigned int adapter_id; const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICE= S; @@ -178,7 +177,6 @@ virSCSIDeviceGetDevName(const char *sysfs_prefix, =20 cleanup: VIR_DIR_CLOSE(dir); - VIR_FREE(path); return name; } =20 @@ -192,11 +190,11 @@ virSCSIDeviceNew(const char *sysfs_prefix, bool shareable) { virSCSIDevicePtr dev, ret =3D NULL; - char *sg =3D NULL; - char *vendor_path =3D NULL; - char *model_path =3D NULL; - char *vendor =3D NULL; - char *model =3D NULL; + VIR_AUTOFREE(char *) sg =3D NULL; + VIR_AUTOFREE(char *) vendor_path =3D NULL; + VIR_AUTOFREE(char *) model_path =3D NULL; + VIR_AUTOFREE(char *) vendor =3D NULL; + VIR_AUTOFREE(char *) model =3D NULL; const char *prefix =3D sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_DEVICE= S; =20 if (VIR_ALLOC(dev) < 0) @@ -247,11 +245,6 @@ virSCSIDeviceNew(const char *sysfs_prefix, =20 ret =3D dev; cleanup: - VIR_FREE(sg); - VIR_FREE(vendor); - VIR_FREE(model); - VIR_FREE(vendor_path); - VIR_FREE(model_path); if (!ret) virSCSIDeviceFree(dev); return ret; --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175101221606.3153558761735; Sat, 21 Jul 2018 05:11:41 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 0150B308FBAC; Sat, 21 Jul 2018 12:11:35 +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 B9722194B5; Sat, 21 Jul 2018 12:11:34 +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 6F7924EE0F; Sat, 21 Jul 2018 12:11:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8oiP016565 for ; Sat, 21 Jul 2018 08:08:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id 261F82015E47; Sat, 21 Jul 2018 12:08:50 +0000 (UTC) Received: from mx1.redhat.com (ext-mx16.extmail.prod.ext.phx2.redhat.com [10.5.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1A0D72015E46 for ; Sat, 21 Jul 2018 12:08:45 +0000 (UTC) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4A2E308226A for ; Sat, 21 Jul 2018 12:08:34 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id r1-v6so8966355pgp.11 for ; Sat, 21 Jul 2018 05:08:34 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.32 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=T0NWJoI2ejTeR5H2roMj7vZ0ggWV1KMMCK60NL9wM3Q=; b=b2HoMtmDj7aPrk4JrZ6620UQJQZ1sfp2VHW6k0sOLU1F0oASSBx+J0SPlBF/aG1oQA O823NBBVAqc55nrOKW5M0KrwTXft2bMk54+DdULek6kcZ9L1Kn5cki3z/LMG5qHHyH1c GdAle0p8+jsgwJX4VYIj40Oh0v0N0oZUIaLvZtEg2PMJSKfyIq+RClfOYb1wfIbM+Mao cXh7XXdi04ezpI4YqayEZPe7wDbAEAre6GiNG+s5X4TR+hj+Q6lP4l7FvxAPhwy/fA9v B14nOkx8BfETDiiW9ydapZkBsiW0zXkPKFe2LgJy/i8kMnRJVLB/Hk/e965oseWeCpAf M6PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=T0NWJoI2ejTeR5H2roMj7vZ0ggWV1KMMCK60NL9wM3Q=; b=Xs+kBfgEBnFrpqgk7cFZNPeLzUxwMazHWd8jGBL3mMCNCO7yUC9Q+hdHJ67M1SvUzV vLqmXMR17XVYKmtc5kgesDdQYJQOjo6xRYswIVDdlsoAU8z6B0kBwC27S+IU0v6S+qbk NfXyz1lj0anaNjCaoLU+pDNSDUpHMQa+uRsB76drhIZbBrtglUWUzfVg9p/yekAPFyW0 ga4Rnc2wIiCD4D9fsG+I7JcNUGBTd/6IJ2XRwwLJ0WwEANjOnGF5ZWLFcePWhXDRflGV zGg5Rail3kEmZF7WSnglg7VahE3UqQCZOsD376RHe+7zJLh9xTxlSU6EP4Q/hj5f389/ oShA== X-Gm-Message-State: AOUpUlEsj7OHjdf8/+0RQCMlSuQEysELzDVFr51XKvORxfBsykUAZWmm UcOEpM4VL+8TeTPuctri+3i668T5 X-Google-Smtp-Source: AAOMgpdVsQpw7MihLrKuL/4yNVfPxG2yLtTKjMZq+wXpGjxii9aOiw30u16zK0RMYhQSxjn09qsPqA== X-Received: by 2002:a63:d80f:: with SMTP id b15-v6mr5500885pgh.347.1532174914067; Sat, 21 Jul 2018 05:08:34 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:00 +0530 Message-Id: <1532174832-21644-29-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 21 Jul 2018 12:08:34 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 21 Jul 2018 12:08:34 +0000 (UTC) for IP:'209.85.215.171' DOMAIN:'mail-pg1-f171.google.com' HELO:'mail-pg1-f171.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.215.171 mail-pg1-f171.google.com 209.85.215.171 mail-pg1-f171.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.45 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 28/40] util: scsi: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Sat, 21 Jul 2018 12:11:40 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virscsi.c | 38 ++++++++++++++++---------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/util/virscsi.c b/src/util/virscsi.c index ba0a688..abe699b 100644 --- a/src/util/virscsi.c +++ b/src/util/virscsi.c @@ -189,7 +189,8 @@ virSCSIDeviceNew(const char *sysfs_prefix, bool readonly, bool shareable) { - virSCSIDevicePtr dev, ret =3D NULL; + VIR_AUTOPTR(virSCSIDevice) dev =3D NULL; + virSCSIDevicePtr ret =3D NULL; VIR_AUTOFREE(char *) sg =3D NULL; VIR_AUTOFREE(char *) vendor_path =3D NULL; VIR_AUTOFREE(char *) model_path =3D NULL; @@ -207,46 +208,44 @@ virSCSIDeviceNew(const char *sysfs_prefix, dev->shareable =3D shareable; =20 if (!(sg =3D virSCSIDeviceGetSgName(prefix, adapter, bus, target, unit= ))) - goto cleanup; + return NULL; =20 if (virSCSIDeviceGetAdapterId(adapter, &dev->adapter) < 0) - goto cleanup; + return NULL; =20 if (virAsprintf(&dev->name, "%d:%u:%u:%llu", dev->adapter, dev->bus, dev->target, dev->unit) < 0 || virAsprintf(&dev->sg_path, "%s/%s", sysfs_prefix ? sysfs_prefix : "/dev", sg) < 0) - goto cleanup; + return NULL; =20 if (!virFileExists(dev->sg_path)) { virReportSystemError(errno, _("SCSI device '%s': could not access %s"), dev->name, dev->sg_path); - goto cleanup; + return NULL; } =20 if (virAsprintf(&vendor_path, "%s/%s/vendor", prefix, dev->name) < 0 || virAsprintf(&model_path, "%s/%s/model", prefix, dev->name) < 0) - goto cleanup; + return NULL; =20 if (virFileReadAll(vendor_path, 1024, &vendor) < 0) - goto cleanup; + return NULL; =20 if (virFileReadAll(model_path, 1024, &model) < 0) - goto cleanup; + return NULL; =20 virTrimSpaces(vendor, NULL); virTrimSpaces(model, NULL); =20 if (virAsprintf(&dev->id, "%s:%s", vendor, model) < 0) - goto cleanup; + return NULL; =20 ret =3D dev; - cleanup: - if (!ret) - virSCSIDeviceFree(dev); + dev =3D NULL; return ret; } =20 @@ -281,21 +280,17 @@ virSCSIDeviceSetUsedBy(virSCSIDevicePtr dev, const char *drvname, const char *domname) { - virUsedByInfoPtr copy; + VIR_AUTOPTR(virUsedByInfo) copy =3D NULL; if (VIR_ALLOC(copy) < 0) return -1; if (VIR_STRDUP(copy->drvname, drvname) < 0 || VIR_STRDUP(copy->domname, domname) < 0) - goto cleanup; + return -1; =20 if (VIR_APPEND_ELEMENT(dev->used_by, dev->n_used_by, copy) < 0) - goto cleanup; + return -1; =20 return 0; - - cleanup: - virSCSIDeviceUsedByInfoFree(copy); - return -1; } =20 bool @@ -442,7 +437,6 @@ virSCSIDeviceListDel(virSCSIDeviceListPtr list, const char *drvname, const char *domname) { - virSCSIDevicePtr tmp =3D NULL; size_t i; =20 for (i =3D 0; i < dev->n_used_by; i++) { @@ -452,8 +446,8 @@ virSCSIDeviceListDel(virSCSIDeviceListPtr list, virSCSIDeviceUsedByInfoFree(dev->used_by[i]); VIR_DELETE_ELEMENT(dev->used_by, i, dev->n_used_by); } else { - tmp =3D virSCSIDeviceListSteal(list, dev); - virSCSIDeviceFree(tmp); + VIR_AUTOPTR(virSCSIDevice) tmp =3D + virSCSIDeviceListSteal(list, dev); } break; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175025726536.8035343266923; Sat, 21 Jul 2018 05:10:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61F0C87628; Sat, 21 Jul 2018 12:10:24 +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 2F0EC2015989; Sat, 21 Jul 2018 12:10:24 +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 D2FA41841C68; Sat, 21 Jul 2018 12:10:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC9CXb016682 for ; Sat, 21 Jul 2018 08:09:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A149308332E; Sat, 21 Jul 2018 12:09:12 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 031013001A50 for ; Sat, 21 Jul 2018 12:08:47 +0000 (UTC) Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C3D99FEC9 for ; Sat, 21 Jul 2018 12:08:36 +0000 (UTC) Received: by mail-pg1-f171.google.com with SMTP id e6-v6so8969589pgv.2 for ; Sat, 21 Jul 2018 05:08:36 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.34 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=nL9QjFMDWa8jcXOVVElusJj/oX/MGeACs11QIaRlt2c=; b=rudERex046HxYOwYZLEiUcnL6mcWL/ZuxHbE2CY5xyz+8OzC7IMmpbb7ij4xFuEmN9 T3EP/hUOeLwmONWWdc+CruDStcjTzP3bbFBR0/aspAHrFBE5qulVPnxsh2sMRH/4tkJ+ QRyBMxS75FAW6m1hMvKTsrC6Q47x3O2NV98m5Gkbp7GYntA2URMptLXBMatjRTmnQXrQ x13FyIumxCqr/ueCCsl/AFBS0Bx/eU8cFXxDgFce5W7ATryxOk0xWCBQCxGHpqn5m0mg 1hPkriEULtXthDbhz0jfzXPRZaOo8HKthIz54RSuT7JzFHkY4s+kPbPniq/10w98b4oi 8hKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=nL9QjFMDWa8jcXOVVElusJj/oX/MGeACs11QIaRlt2c=; b=tk/C71jYP9lI5T8dQXuU5mfN05k3IhXL3AXvQ3efxq/itR5MMwXCVnuXECKMsLRIgo wHV0lNBEmjAH2idZyyks0c6regbX+Izzm/b82wsBevznvhdN+ytgH5Hqlog+PSzSeMrF 70F3XW07FSp7NELp9yV5Uz+dBJf16hLkWOOVldm6Ys+dfWcu90LPP7Bj55jWNnDB/aJ2 SCAQ3bQW3g3XUXs7CDxGbs6F8MKFlzZ0wKkiRraw2Xdi//2dUo/ta14eICfGg6tk2Yef O3ick/72fPrLZhXq23XLt5XlvYQKKjfjvtp1re5BDbRkAhdnu5A0qUK4q6N3lF2odMLu fFTw== X-Gm-Message-State: AOUpUlE/JS8Yt0TnI1HS3ghAMroogO/brfiKe8XOU6zfZR9BKTfq4RDK 8sbP9B11vLSQpNhXSPgFsVVOFhe+ X-Google-Smtp-Source: AAOMgpfy9ayVIMRxJMsghkim4oXGGioBtaCjzC7vyGuCzkigKcyXL0UtSIClNXeg9YvuSiksE3LCTA== X-Received: by 2002:a63:ed03:: with SMTP id d3-v6mr5470379pgi.56.1532174916093; Sat, 21 Jul 2018 05:08:36 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:01 +0530 Message-Id: <1532174832-21644-30-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 21 Jul 2018 12:08:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 21 Jul 2018 12:08:36 +0000 (UTC) for IP:'209.85.215.171' DOMAIN:'mail-pg1-f171.google.com' HELO:'mail-pg1-f171.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.3 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_PASS, T_DKIM_INVALID) 209.85.215.171 mail-pg1-f171.google.com 209.85.215.171 mail-pg1-f171.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 29/40] util: scsivhost: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:10:25 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virSCSIVHostDevicePtr is declared using VIR_AUTOPTR, the function virSCSIVHostDeviceFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virscsivhost.c | 1 - src/util/virscsivhost.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c index 84c09e8..ef216b3 100644 --- a/src/util/virscsivhost.c +++ b/src/util/virscsivhost.c @@ -26,7 +26,6 @@ =20 #include "virscsivhost.h" #include "virlog.h" -#include "viralloc.h" #include "virerror.h" #include "virfile.h" #include "virstring.h" diff --git a/src/util/virscsivhost.h b/src/util/virscsivhost.h index 21887dd..31ad429 100644 --- a/src/util/virscsivhost.h +++ b/src/util/virscsivhost.h @@ -27,6 +27,7 @@ # include "internal.h" # include "virobject.h" # include "virutil.h" +# include "viralloc.h" =20 typedef struct _virSCSIVHostDevice virSCSIVHostDevice; typedef virSCSIVHostDevice *virSCSIVHostDevicePtr; @@ -63,4 +64,6 @@ void virSCSIVHostDeviceGetUsedBy(virSCSIVHostDevicePtr de= v, void virSCSIVHostDeviceFree(virSCSIVHostDevicePtr dev); int virSCSIVHostOpenVhostSCSI(int *vhostfd) ATTRIBUTE_NOINLINE; =20 +VIR_DEFINE_AUTOPTR_FUNC(virSCSIVHostDevice, virSCSIVHostDeviceFree) + #endif /* __VIR_SCSIHOST_H__ */ --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175295263432.41429161599035; Sat, 21 Jul 2018 05:14:55 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D83D5308226E; Sat, 21 Jul 2018 12:14:53 +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 94AAB5D6B4; Sat, 21 Jul 2018 12:14:53 +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 0AA881841C4A; Sat, 21 Jul 2018 12:14:53 +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 w6LC9Dta016706 for ; Sat, 21 Jul 2018 08:09:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id BBFDE60C9A; Sat, 21 Jul 2018 12:09:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2C3B60BE7 for ; Sat, 21 Jul 2018 12:08:49 +0000 (UTC) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D4CDC0587E3 for ; Sat, 21 Jul 2018 12:08:38 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id z8-v6so8966415pgu.8 for ; Sat, 21 Jul 2018 05:08:38 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=btnnG8wKOJhSePti/mIcYDMVIeuZL2SfacWumhJtdMs=; b=IzgOPwpJrOeNfIflZeSnjJe6CZ31VhmUMZenW8RIdMBGTpiHQHGdzZjPx9U1ChwZKw B4CSSC0F6HtxNHtj43P6388UF/zknBzXQoa1VGZv+WRH1Ek2u+AFd0SzLIfjyWbbZJ1U 5bTDiidW8H0UENd3blmUDVOTFIg8aF4La89fkR6IS3nHGqX7U5CprvAKw5tJ8Cm2xChM N7mV/xZGFEyWLeBpStbE9RJhVHY92w16YcVByP9BKiegURLkw8aXMja3esbFtq+ouzPC bHXg8dI5zPqmQtMnr7xkxgNTz51blg5nUDnNgBN/NwobAq+gZLdIQ3jMzRf9MeudlERE XmVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=btnnG8wKOJhSePti/mIcYDMVIeuZL2SfacWumhJtdMs=; b=qJ2ZDJd6inz85BGU8mM8n1snyD11vi7vAYbTRlhy+4Gz00+RefMv/zPM7AueE7jbsM tcqUkpap5ruelkBeY3GLWuCZbT0FklKlIQ5SMF6R/jv4T6ErYx+KZrYvvO1OzDvmanTX DDxHzuDWDSskvCeowZ+34WqDC+HGpBgGtyGnG+nhf7F3pIyW7awIpvpZj4LjM/3yllDS HWzOh8xjFUkVg5m6z7Xy6rky6wr0UptWL/MCWeW/f19ZZsL0KQ8tS3LRh/1hgyvk2rxV nIQj6q/bqUtnhUKFXHQ4v9Fu36q+pc3u0+6BZO3D8pT5tqdRhLlLTeNnry9mesTuqkS7 r9iA== X-Gm-Message-State: AOUpUlFNSkNNSdSFedrj78QQ4/zanBjH+dUG91eMSXrrmro3uqahkySg M4gmc1LnwojHo36rCHeNfMLiL2JF X-Google-Smtp-Source: AAOMgpeQUn0DoPrENkPWixeEQJAExhiUVNjIx8Sk2HuBp+Ob19sgtaVjXby0RtNJYF8SDLoh1++Xlg== X-Received: by 2002:a63:1644:: with SMTP id 4-v6mr5540858pgw.103.1532174917928; Sat, 21 Jul 2018 05:08:37 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:02 +0530 Message-Id: <1532174832-21644-31-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:08:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 21 Jul 2018 12:08:38 +0000 (UTC) for IP:'209.85.215.177' DOMAIN:'mail-pg1-f177.google.com' HELO:'mail-pg1-f177.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.177 mail-pg1-f177.google.com 209.85.215.177 mail-pg1-f177.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 30/40] util: scsivhost: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 21 Jul 2018 12:14:54 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virscsivhost.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/util/virscsivhost.c b/src/util/virscsivhost.c index ef216b3..3cd421e 100644 --- a/src/util/virscsivhost.c +++ b/src/util/virscsivhost.c @@ -109,8 +109,7 @@ void virSCSIVHostDeviceListDel(virSCSIVHostDeviceListPtr list, virSCSIVHostDevicePtr dev) { - virSCSIVHostDevicePtr tmp =3D virSCSIVHostDeviceListSteal(list, dev); - virSCSIVHostDeviceFree(tmp); + VIR_AUTOPTR(virSCSIVHostDevice) tmp =3D virSCSIVHostDeviceListSteal(li= st, dev); } =20 =20 @@ -271,13 +270,11 @@ virSCSIVHostDeviceNew(const char *name) =20 VIR_DEBUG("%s: initialized", dev->name); =20 - cleanup: return dev; =20 error: virSCSIVHostDeviceFree(dev); - dev =3D NULL; - goto cleanup; + return NULL; } =20 =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175154914756.2543128277326; Sat, 21 Jul 2018 05:12:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 12BEC87644; Sat, 21 Jul 2018 12:12:25 +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 D671D5D76F; Sat, 21 Jul 2018 12:12:24 +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 8D6DD1841C4A; Sat, 21 Jul 2018 12:12:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC90M6016612 for ; Sat, 21 Jul 2018 08:09:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 68B9A1062246; Sat, 21 Jul 2018 12:09:00 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E0E2101F97D for ; Sat, 21 Jul 2018 12:08:51 +0000 (UTC) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE5ECC04B940 for ; Sat, 21 Jul 2018 12:08:40 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id y4-v6so8960965pgp.9 for ; Sat, 21 Jul 2018 05:08:40 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=3zXyA1x+cLxDjHMemVOlcE6bn3Dr9Q8SBY+/F4tAlPI=; b=D27r8Pwgu8dLhbXLHpBheGnXBsXbxktNk/eol8cHbhIIHqp+bPVwOSNQbxdIZByjxG nlE7zQgCEFyMSz0Jrvp7AnRYBD4w+jhUoZTkKoPhZgP0TnNmvKrg1jkXzjQ2ztCtc9xj i/z5q8BdVzsNnxWXzEr8fJ0GUisO9rnMUat8vcuPGn/5ionA41KACywdjZ4nnEcBCU0K GikOG7/JyhBLRmvEV/JPwrI12lWSzeLaJVr2Y68JXvu/BIc54zHFkZ+sGUKBMrJhPn4K HSnPLeApTkGN/ydwAEuBn/FBJOOhnJNKRiS0fDPoxsMauTs2MD52huE88oeIaPjePzYA UL4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=3zXyA1x+cLxDjHMemVOlcE6bn3Dr9Q8SBY+/F4tAlPI=; b=iapCXEm0wGeMvix0k2ov0UILiCAcpjMCItyd2X6gcI7lQR7a21ZzLWkRISliZyXGB6 OaZx9XnI6l5W+ged5y9N43HCq3SHTyRdv/NvkXde6ylYgzPvEM8/5QKm8ioJfGkKdLZq BHza5n2/Go8eye2iHq5AVR2f5M7rsVJLXBjMgFJp+qG52zodHeAzN20cC8+015vN0Rsd zRzmE8X3FeoxJTeqGkDG2AN0PdeM5Je1pQS1Azu26DR77WubF8tXwoelYL7yZ+Jb2+7i GR+0+X9v04iJYOQFAcDwJJeFv8Bh2VYzv1CEYPxY5Ga05FHz0ato3BVjb8qsUsT9oklb ZHrw== X-Gm-Message-State: AOUpUlHxRCt6v0KbaAGeZCvvVOg74vp33t1+tkQ3DtzY1MXDXYF1ycfJ HN/KvUhoqKm+or2NQTf4vefaYfBw X-Google-Smtp-Source: AAOMgpd+56y/bjoQfR2d1M2BWaeNtt//v1/YId94WzLLPuGIjXlMGmyxcqSjF71g1hQ6/OP+lQSC/A== X-Received: by 2002:a65:5307:: with SMTP id m7-v6mr5546426pgq.431.1532174920158; Sat, 21 Jul 2018 05:08:40 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:03 +0530 Message-Id: <1532174832-21644-32-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 21 Jul 2018 12:08:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 21 Jul 2018 12:08:41 +0000 (UTC) for IP:'209.85.215.170' DOMAIN:'mail-pg1-f170.google.com' HELO:'mail-pg1-f170.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.170 mail-pg1-f170.google.com 209.85.215.170 mail-pg1-f170.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 31/40] util: hostdev: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:12:34 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virhostdev.c | 91 +++++++++++++++++------------------------------= ---- 1 file changed, 30 insertions(+), 61 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index f4bd19d..c4335a9 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -186,17 +186,14 @@ virHostdevManagerNew(void) goto error; } } else { - char *rundir =3D NULL; + VIR_AUTOFREE(char *) rundir =3D NULL; mode_t old_umask; =20 if (!(rundir =3D virGetUserRuntimeDirectory())) goto error; =20 - if (virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir) < = 0) { - VIR_FREE(rundir); + if (virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir) < = 0) goto error; - } - VIR_FREE(rundir); =20 old_umask =3D umask(077); =20 @@ -289,17 +286,12 @@ virHostdevPCISysfsPath(virDomainHostdevDefPtr hostdev, static int virHostdevIsVirtualFunction(virDomainHostdevDefPtr hostdev) { - char *sysfs_path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) sysfs_path =3D NULL; =20 if (virHostdevPCISysfsPath(hostdev, &sysfs_path) < 0) - return ret; + return -1; =20 - ret =3D virPCIIsVirtualFunction(sysfs_path); - - VIR_FREE(sysfs_path); - - return ret; + return virPCIIsVirtualFunction(sysfs_path); } =20 =20 @@ -309,17 +301,15 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev, char **linkdev, int *vf) { - int ret =3D -1; - char *sysfs_path =3D NULL; + VIR_AUTOFREE(char *) sysfs_path =3D NULL; =20 if (virHostdevPCISysfsPath(hostdev, &sysfs_path) < 0) - return ret; + return -1; =20 if (virPCIIsVirtualFunction(sysfs_path) =3D=3D 1) { if (virPCIGetVirtualFunctionInfo(sysfs_path, pfNetDevIdx, - linkdev, vf) < 0) { - goto cleanup; - } + linkdev, vf) < 0) + return -1; } else { /* In practice this should never happen, since we currently * only support assigning SRIOV VFs via parent.data.net); virtPort =3D virDomainNetGetActualVirtPortProfile(hostdev->parent.data= .net); @@ -507,24 +487,19 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev, _("direct setting of the vlan tag is not allowe= d " "for hostdev devices using %s mode"), virNetDevVPortTypeToString(virtPort->virtPortTy= pe)); - goto cleanup; + return -1; } if (virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, &hostdev->parent.data.net->= mac, - uuid, port_profile_associat= e) < 0) { - goto cleanup; - } + uuid, port_profile_associat= e) < 0) + return -1; } else { if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent.data.net->= mac, - vlan, NULL, true) < 0) { - goto cleanup; - } + vlan, NULL, true) < 0) + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(linkdev); - return ret; + return 0; } =20 =20 @@ -540,13 +515,13 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hos= tdev, const char *stateDir, const char *oldStateDir) { - char *linkdev =3D NULL; + VIR_AUTOFREE(char *) linkdev =3D NULL; + VIR_AUTOFREE(virMacAddrPtr) MAC =3D NULL; + VIR_AUTOFREE(virMacAddrPtr) adminMAC =3D NULL; virNetDevVPortProfilePtr virtPort; int ret =3D -1; int vf =3D -1; bool port_profile_associate =3D false; - virMacAddrPtr MAC =3D NULL; - virMacAddrPtr adminMAC =3D NULL; virNetDevVlanPtr vlan =3D NULL; =20 =20 @@ -656,9 +631,6 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostd= ev, } =20 cleanup: - VIR_FREE(linkdev); - VIR_FREE(MAC); - VIR_FREE(adminMAC); virNetDevVlanFree(vlan); =20 return ret; @@ -763,8 +735,8 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, mgr->inactivePCIHostdevs) < 0) goto reattachdevs; } else { - char *driverPath; - char *driverName; + VIR_AUTOFREE(char *) driverPath =3D NULL; + VIR_AUTOFREE(char *) driverName =3D NULL; int stub; =20 /* Unmanaged devices should already have been marked as @@ -790,9 +762,6 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, =20 stub =3D virPCIStubDriverTypeFromString(driverName); =20 - VIR_FREE(driverPath); - VIR_FREE(driverName); - if (stub > VIR_PCI_STUB_DRIVER_NONE && stub < VIR_PCI_STUB_DRIVER_LAST) { =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153217527018846.009872690204475; Sat, 21 Jul 2018 05:14:30 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B6A7981DE3; Sat, 21 Jul 2018 12:14:28 +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 3CAF45C20D; Sat, 21 Jul 2018 12:14:28 +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 967AC4EE0B; Sat, 21 Jul 2018 12:14:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC9Dbw016699 for ; Sat, 21 Jul 2018 08:09:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2E21616EFE; Sat, 21 Jul 2018 12:09:13 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2304917017 for ; Sat, 21 Jul 2018 12:08:55 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA1C885545 for ; Sat, 21 Jul 2018 12:08:43 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id g2-v6so8972235pgs.6 for ; Sat, 21 Jul 2018 05:08:43 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=UdsTM0c2LYMlmlQhW7aC/xgchL3/F9coAnZClbgYtgc=; b=EfQMgONFSGd2Q7oeENc3GtGWTjB+mo184/vMygacDJXGlO5ee0UfzyhkDXnCc9hRgF wx5ND7N3w9XsNTWHM/qym280ooeT3iMkc8FlCCE5wJ4bhhcLMk29HyPxIxFDwZBJHZuB Q7cwNJR5ZwSTCbRH+AbGnWFNrDhRxnurAl//v7fEgQgj4c1aF+JP4spiOSDFhTLt8uTD s2sSRam/aShmorpUH8dS1tYoDGxpiyEQdFtl4+FgZ6v+gojdfpV6H7U0sDoChqonbCBU imGbo5/XfqG7LcnBa8UYSlfprekQYHM5vP9OrNpscA1IUOmaPK6IDIIG7cZF004bN6t1 4A1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=UdsTM0c2LYMlmlQhW7aC/xgchL3/F9coAnZClbgYtgc=; b=i81tNekev/i5XMZME4lIfp+n4WGb/RXFQcE4XQQIXnwBypB5vrR4ZM5ReUVQQyFXWV T2z4fE5KisK4XOSS+6KQVDs5s+Lk+KMU1L/kDqNfx+uIURtg+59Nq58HfTiaIMnTNXFE mXl4KX+Rwf1MMzuSklQLLGP551nWMO9hAD8qeZflm2TQVUgrK5wI9X7hB2AI1GwLsskc oy9wxrC6sByzNYgsT+e2iVCXqsEzMOuRjlj/o4lWM2uBjCZIwkLdNDnbyU9Yj+tRQkyb Rug7ItU7ZmSNqNoj0GMgLhYaLHI54njMhXx+XEwHFPufO3Yn27JgLQ/Mp6oocTsuAqjH Sy7g== X-Gm-Message-State: AOUpUlH6bTkR9HmdUsjxIzSKOS7b1UL81GXWBFk4qY4GgYlQ8oDRkuTG IpQGQ0mcdcJ40s9ri9ekvsb2od45 X-Google-Smtp-Source: AAOMgpdx+InxtstadTeFq42uVZLQ0vznHG4PaLDqsUZ6QAcw/KdfsW2gxaTCmJhX4Ww+63lqWH+0cA== X-Received: by 2002:a63:f919:: with SMTP id h25-v6mr5269571pgi.401.1532174923142; Sat, 21 Jul 2018 05:08:43 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:04 +0530 Message-Id: <1532174832-21644-33-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 21 Jul 2018 12:08:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 21 Jul 2018 12:08:44 +0000 (UTC) for IP:'209.85.215.195' DOMAIN:'mail-pg1-f195.google.com' HELO:'mail-pg1-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.195 mail-pg1-f195.google.com 209.85.215.195 mail-pg1-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 32/40] util: hostdev: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 21 Jul 2018 12:14:29 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virhostdev.c | 71 ++++++++++++++++++-----------------------------= ---- 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index c4335a9..b5315b1 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -518,11 +518,10 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hos= tdev, VIR_AUTOFREE(char *) linkdev =3D NULL; VIR_AUTOFREE(virMacAddrPtr) MAC =3D NULL; VIR_AUTOFREE(virMacAddrPtr) adminMAC =3D NULL; + VIR_AUTOPTR(virNetDevVlan) vlan =3D NULL; virNetDevVPortProfilePtr virtPort; - int ret =3D -1; int vf =3D -1; bool port_profile_associate =3D false; - virNetDevVlanPtr vlan =3D NULL; =20 =20 /* This is only needed for PCI devices that have been defined @@ -535,16 +534,16 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hos= tdev, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Interface type hostdev is currently supported on" " SR-IOV Virtual Functions only")); - return ret; + return -1; } =20 if (virHostdevNetDevice(hostdev, 0, &linkdev, &vf) < 0) - return ret; + return -1; =20 virtPort =3D virDomainNetGetActualVirtPortProfile( hostdev->parent.data.net); if (virtPort) { - ret =3D virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, + return virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, &hostdev->parent.data.net= ->mac, NULL, port_profile_associate); @@ -574,7 +573,7 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostd= ev, /* 1) standard location */ if (virNetDevReadNetConfig(linkdev, vf, stateDir, &adminMAC, &vlan, &MAC) < 0) { - goto cleanup; + return -1; } =20 /* 2) "old" (pre-1.2.3 circa 2014) location - whenever we get @@ -585,7 +584,7 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostd= ev, if (!(adminMAC || vlan || MAC) && oldStateDir && virNetDevReadNetConfig(linkdev, vf, oldStateDir, &adminMAC, &vlan, &MAC) < 0) { - goto cleanup; + return -1; } =20 /* 3) try using the PF's "port 2" netdev as the name of the @@ -597,7 +596,7 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostd= ev, if (virHostdevNetDevice(hostdev, 1, &linkdev, &vf) < 0 || virNetDevReadNetConfig(linkdev, vf, stateDir, &adminMAC, &vlan, &MAC) < 0) { - goto cleanup; + return -1; } } =20 @@ -627,13 +626,8 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr host= dev, =20 ignore_value(virNetDevSetNetConfig(linkdev, vf, adminMAC, vlan, MAC, true)); - ret =3D 0; + return 0; } - - cleanup: - virNetDevVlanFree(vlan); - - return ret; } =20 int @@ -1117,7 +1111,6 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr= mgr, const char *dom_name) { virDomainHostdevDefPtr hostdev =3D NULL; - virPCIDevicePtr actual =3D NULL; size_t i; int ret =3D -1; =20 @@ -1128,6 +1121,7 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr= mgr, virObjectLock(mgr->inactivePCIHostdevs); =20 for (i =3D 0; i < nhostdevs; i++) { + VIR_AUTOPTR(virPCIDevice) actual =3D NULL; virDomainHostdevSubsysPCIPtr pcisrc; hostdev =3D hostdevs[i]; pcisrc =3D &hostdev->source.subsys.u.pci; @@ -1165,7 +1159,6 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr= mgr, =20 ret =3D 0; cleanup: - virPCIDeviceFree(actual); virObjectUnlock(mgr->activePCIHostdevs); virObjectUnlock(mgr->inactivePCIHostdevs); return ret; @@ -1226,31 +1219,27 @@ virHostdevUpdateActiveSCSIHostDevices(virHostdevMan= agerPtr mgr, virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; virSCSIDevicePtr scsi =3D NULL; virSCSIDevicePtr tmp =3D NULL; - int ret =3D -1; =20 if (!(scsi =3D virSCSIDeviceNew(NULL, scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit, hostdev->readonly, hostdev->shareable))) - goto cleanup; + return -1; =20 if ((tmp =3D virSCSIDeviceListFind(mgr->activeSCSIHostdevs, scsi))) { if (virSCSIDeviceSetUsedBy(tmp, drv_name, dom_name) < 0) { virSCSIDeviceFree(scsi); - goto cleanup; + return -1; } virSCSIDeviceFree(scsi); } else { if (virSCSIDeviceSetUsedBy(scsi, drv_name, dom_name) < 0 || virSCSIDeviceListAdd(mgr->activeSCSIHostdevs, scsi) < 0) { virSCSIDeviceFree(scsi); - goto cleanup; + return -1; } } - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 int @@ -1301,7 +1290,7 @@ virHostdevUpdateActiveMediatedDevices(virHostdevManag= erPtr mgr, { int ret =3D -1; size_t i; - virMediatedDevicePtr mdev =3D NULL; + VIR_AUTOPTR(virMediatedDevice) mdev =3D NULL; =20 if (nhostdevs =3D=3D 0) return 0; @@ -1327,7 +1316,6 @@ virHostdevUpdateActiveMediatedDevices(virHostdevManag= erPtr mgr, =20 ret =3D 0; cleanup: - virMediatedDeviceFree(mdev); virObjectUnlock(mgr->activeMediatedHostdevs); return ret; } @@ -1560,29 +1548,25 @@ virHostdevPrepareSCSIHostDevices(virDomainHostdevDe= fPtr hostdev, { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; virSCSIDevicePtr scsi; - int ret =3D -1; =20 if (hostdev->managed) { virReportError(VIR_ERR_XML_ERROR, "%s", _("SCSI host device doesn't support managed mode")); - goto cleanup; + return -1; } =20 if (!(scsi =3D virSCSIDeviceNew(NULL, scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit, hostdev->readonly, hostdev->shareable))) - goto cleanup; + return -1; =20 if (virSCSIDeviceListAdd(list, scsi) < 0) { virSCSIDeviceFree(scsi); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 int @@ -1859,7 +1843,8 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr mgr, for (i =3D 0; i < nhostdevs; i++) { virDomainHostdevDefPtr hostdev =3D hostdevs[i]; virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; - virUSBDevicePtr usb, tmp; + VIR_AUTOPTR(virUSBDevice) usb =3D NULL; + virUSBDevicePtr tmp; const char *usedby_drvname; const char *usedby_domname; =20 @@ -1883,7 +1868,6 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr mgr, * the list which were taken by @name */ =20 tmp =3D virUSBDeviceListFind(mgr->activeUSBHostdevs, usb); - virUSBDeviceFree(usb); =20 if (!tmp) { VIR_WARN("Unable to find device %03d.%03d " @@ -1911,7 +1895,7 @@ virHostdevReAttachSCSIHostDevices(virHostdevManagerPt= r mgr, const char *dom_name) { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; - virSCSIDevicePtr scsi; + VIR_AUTOPTR(virSCSIDevice) scsi =3D NULL; virSCSIDevicePtr tmp; =20 if (!(scsi =3D virSCSIDeviceNew(NULL, @@ -1932,7 +1916,6 @@ virHostdevReAttachSCSIHostDevices(virHostdevManagerPt= r mgr, "in list of active SCSI devices", scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit); - virSCSIDeviceFree(scsi); return; } =20 @@ -1942,7 +1925,6 @@ virHostdevReAttachSCSIHostDevices(virHostdevManagerPt= r mgr, =20 virSCSIDeviceListDel(mgr->activeSCSIHostdevs, tmp, drv_name, dom_name); - virSCSIDeviceFree(scsi); } =20 void @@ -1982,14 +1964,14 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManage= rPtr mgr, int nhostdevs) { size_t i; - virSCSIVHostDevicePtr host, tmp; - =20 if (!nhostdevs) return; =20 virObjectLock(mgr->activeSCSIVHostHostdevs); for (i =3D 0; i < nhostdevs; i++) { + VIR_AUTOPTR(virSCSIVHostDevice) host =3D NULL; + virSCSIVHostDevicePtr tmp; virDomainHostdevDefPtr hostdev =3D hostdevs[i]; virDomainHostdevSubsysSCSIVHostPtr hostsrc =3D &hostdev->source.su= bsys.u.scsi_host; const char *usedby_drvname; @@ -2017,7 +1999,6 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManagerP= tr mgr, VIR_WARN("Unable to find device %s " "in list of active SCSI_host devices", hostsrc->wwpn); - virSCSIVHostDeviceFree(host); virObjectUnlock(mgr->activeSCSIVHostHostdevs); return; } @@ -2031,8 +2012,6 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManagerP= tr mgr, =20 virSCSIVHostDeviceListDel(mgr->activeSCSIVHostHostdevs, tmp); } - - virSCSIVHostDeviceFree(host); } virObjectUnlock(mgr->activeSCSIVHostHostdevs); } @@ -2060,7 +2039,8 @@ virHostdevReAttachMediatedDevices(virHostdevManagerPt= r mgr, =20 virObjectLock(mgr->activeMediatedHostdevs); for (i =3D 0; i < nhostdevs; i++) { - virMediatedDevicePtr mdev, tmp; + VIR_AUTOPTR(virMediatedDevice) mdev =3D NULL; + virMediatedDevicePtr tmp; virDomainHostdevSubsysMediatedDevPtr mdevsrc; virDomainHostdevDefPtr hostdev =3D hostdevs[i]; =20 @@ -2076,7 +2056,6 @@ virHostdevReAttachMediatedDevices(virHostdevManagerPt= r mgr, /* Remove from the list only mdevs assigned to @drv_name/@dom_name= */ =20 tmp =3D virMediatedDeviceListFind(mgr->activeMediatedHostdevs, mde= v); - virMediatedDeviceFree(mdev); =20 /* skip inactive devices */ if (!tmp) --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175242558656.632939494866; Sat, 21 Jul 2018 05:14:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EFBB30832D3; Sat, 21 Jul 2018 12:14:01 +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 03146308BDAC; Sat, 21 Jul 2018 12:14:01 +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 AC5461841C4B; Sat, 21 Jul 2018 12:14:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC9BuZ016677 for ; Sat, 21 Jul 2018 08:09:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id EFD53608F7; Sat, 21 Jul 2018 12:09:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E5101608F8 for ; Sat, 21 Jul 2018 12:08:57 +0000 (UTC) Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 825833081244 for ; Sat, 21 Jul 2018 12:08:46 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id n7-v6so8961581pgq.4 for ; Sat, 21 Jul 2018 05:08:46 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=yHtLLI/+XTf9vQmuGLQnxQQQ+K1W+Ydr1PQDtUL3icE=; b=UxXZko7FuTz7n9W32QKvX/2qEfAG0pwPgQ4OZw8xfMrH4gLA75oeb7WagbuXjDWI1n ZpaDpc+2XZ4w66BZCAysWYvAxem6/CSzyAca8Zd86JWxXobpJ/2Vbm41WhR1O5FqJrtY V6f04YaN0oummuDTcguQDr91Vb28HoA9hx6ZOGUkP9LL2qWKTihlmK1JSTi+8evttwbH MMUN7azAv1Ka0eUnol5B8e26/BQCMCasQlwshSj9FXSUK0BVzcjcbOscCKdXrEIjEhTE 70Te+DHmonyD8P7UUK2EVoDkooVvVA5MUXh5d8lzgqLwFFxGXkSVZ13MX8+KRY5zksqr 9kdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=yHtLLI/+XTf9vQmuGLQnxQQQ+K1W+Ydr1PQDtUL3icE=; b=NFL8BxcmC44ZtiqOuY19cAWoZFMHJoFuMSQDow7knHl3TjGYEeZ5aZxRIdf5wQtiLX o/EVYcw1mlT8q3yfTbJGrWh7I2ab68nzb9urRGxYasiCFUFdQnqFCAtJCG7x8TlttZVY PBsa2her0qHZNIQlz8ImgiYMkfkETUehlu11jDbUpP0kl5wYFnO6LIlYSVLftOzDe5IL R8ESWm01yQIKg2THXseNHVTJ+LRGDD+TmyRBTIAWXS5vi5P3kATq4WKo6zMPdSRdHVmc pZELCBB7dHqx5ePYLKhTm9rqqiDcxxIfsJxK1NwIBYi/fobxecJEviCa10yOrmu1jbJf k7lA== X-Gm-Message-State: AOUpUlH0Pmjyll7Em3gm6jPdY4fOd0cCAJXGyX2iGBVUc+qjWjDp/HrU afFUwVp1bX+MBaSUbIHF6wu6aIHD X-Google-Smtp-Source: AAOMgpcpwzZ4+l+zMvua51k56AB57s9l6v/wtEHTosC+fr2Uw6pCYNCypuMfX80EpFCl7jozyy3QVA== X-Received: by 2002:a63:7b1b:: with SMTP id w27-v6mr5234440pgc.199.1532174925815; Sat, 21 Jul 2018 05:08:45 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:05 +0530 Message-Id: <1532174832-21644-34-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 21 Jul 2018 12:08:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 21 Jul 2018 12:08:46 +0000 (UTC) for IP:'209.85.215.179' DOMAIN:'mail-pg1-f179.google.com' HELO:'mail-pg1-f179.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.179 mail-pg1-f179.google.com 209.85.215.179 mail-pg1-f179.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 33/40] util: hostmem: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 21 Jul 2018 12:14:01 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virhostmem.c | 57 ++++++++++++++++-------------------------------= ---- 1 file changed, 18 insertions(+), 39 deletions(-) diff --git a/src/util/virhostmem.c b/src/util/virhostmem.c index c923a1e..08ed7a5 100644 --- a/src/util/virhostmem.c +++ b/src/util/virhostmem.c @@ -263,7 +263,7 @@ virHostMemGetStats(int cellNum ATTRIBUTE_UNUSED, #ifdef __linux__ { int ret; - char *meminfo_path =3D NULL; + VIR_AUTOFREE(char *) meminfo_path =3D NULL; FILE *meminfo; int max_node; =20 @@ -299,12 +299,10 @@ virHostMemGetStats(int cellNum ATTRIBUTE_UNUSED, if (!meminfo) { virReportSystemError(errno, _("cannot open %s"), meminfo_path); - VIR_FREE(meminfo_path); return -1; } ret =3D virHostMemGetStatsLinux(meminfo, cellNum, params, nparams); VIR_FORCE_FCLOSE(meminfo); - VIR_FREE(meminfo_path); =20 return ret; } @@ -322,45 +320,36 @@ virHostMemGetStats(int cellNum ATTRIBUTE_UNUSED, static int virHostMemSetParameterValue(virTypedParameterPtr param) { - char *path =3D NULL; - char *strval =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) strval =3D NULL; int rc =3D -1; =20 char *field =3D strchr(param->field, '_'); sa_assert(field); field++; if (virAsprintf(&path, "%s/%s", - SYSFS_MEMORY_SHARED_PATH, field) < 0) { - ret =3D -2; - goto cleanup; - } + SYSFS_MEMORY_SHARED_PATH, field) < 0) + return -2; =20 - if (virAsprintf(&strval, "%u", param->value.ui) =3D=3D -1) { - ret =3D -2; - goto cleanup; - } + if (virAsprintf(&strval, "%u", param->value.ui) =3D=3D -1) + return -2; =20 if ((rc =3D virFileWriteStr(path, strval, 0)) < 0) { virReportSystemError(-rc, _("failed to set %s"), param->field); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(strval); - return ret; + return 0; } =20 static bool virHostMemParametersAreAllSupported(virTypedParameterPtr params, int nparams) { - char *path =3D NULL; size_t i; =20 for (i =3D 0; i < nparams; i++) { + VIR_AUTOFREE(char *) path =3D NULL; virTypedParameterPtr param =3D ¶ms[i]; =20 char *field =3D strchr(param->field, '_'); @@ -374,11 +363,8 @@ virHostMemParametersAreAllSupported(virTypedParameterP= tr params, virReportError(VIR_ERR_OPERATION_INVALID, _("Parameter '%s' is not supported by " "this kernel"), param->field); - VIR_FREE(path); return false; } - - VIR_FREE(path); } =20 return true; @@ -430,23 +416,20 @@ static int virHostMemGetParameterValue(const char *field, void *value) { - char *path =3D NULL; - char *buf =3D NULL; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; char *tmp =3D NULL; - int ret =3D -1; int rc =3D -1; =20 if (virAsprintf(&path, "%s/%s", SYSFS_MEMORY_SHARED_PATH, field) < 0) - goto cleanup; + return -1; =20 - if (!virFileExists(path)) { - ret =3D -2; - goto cleanup; - } + if (!virFileExists(path)) + return -2; =20 if (virFileReadAll(path, 1024, &buf) < 0) - goto cleanup; + return -1; =20 if ((tmp =3D strchr(buf, '\n'))) *tmp =3D '\0'; @@ -465,14 +448,10 @@ virHostMemGetParameterValue(const char *field, if (rc < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse %s"), field); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(path); - VIR_FREE(buf); - return ret; + return 0; } #endif =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175003621778.8316292022193; Sat, 21 Jul 2018 05:10:03 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 914EA308214E; Sat, 21 Jul 2018 12:10:01 +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 499211852D; Sat, 21 Jul 2018 12:10:00 +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 DD9554EE13; Sat, 21 Jul 2018 12:09:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC90v0016607 for ; Sat, 21 Jul 2018 08:09:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 223CA5B683; Sat, 21 Jul 2018 12:09:00 +0000 (UTC) Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 15E555B682 for ; Sat, 21 Jul 2018 12:09:00 +0000 (UTC) Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E155030820CD for ; Sat, 21 Jul 2018 12:08:48 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id l9-v6so223535pff.9 for ; Sat, 21 Jul 2018 05:08:48 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=Bdj76KFhmEOQW3139BQq87JbHpHLDmD/3bmuRCYpP7Q=; b=iWKlPVGxiSy5Vevrs8g1U/M8naZ8XRv4drF3iTPQULbTaYylT1m4RovEF/losFNIUI B2zv5m+t3pr9w90owiJJtAHAofuRkHvOiuDdHkAeXVHPIvviXkHEfHz+AH2qbr81nRy2 gKwtWcWSfqrj8jWcgLcgveLCfNyYiiO8g0dt9pBOqzmudfnwnAG6zuEze65F5s2oe2A+ pbQNhhAPBvUTIGelMZXS9JANQc5BC3Rm4kgLsY/1nGvz5xmHPzWdsWVtWWlavIej0yRH TWxe9Ug2HF8nBMU7jZuZJVX7as5zhjNV1AvK/v3HDDBQofRnQVXwVT7RZaAKeACxcfQE C2+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Bdj76KFhmEOQW3139BQq87JbHpHLDmD/3bmuRCYpP7Q=; b=Pk4r8n56YECmInHvphTIfC6s0iBHuqdzEvJXL4Ctfsoyry9ojwIp1UpifBEwoj+EFB lq2b/hqXqIYjlcODbNM6bYBEopW+ym62bC2CStrxdCJcUqA0at6ItMazN8+n1CPgFhdZ wlQ+4hQ/+9Gt0idTnYscf6DF1pLyLk6G5lPXyItyW7CVfmr5qmVg45s21WrVim0YMb/A JpEBdZ4lrBR8hD4iVzdB6lZJBStrZdFAyYWg4W6EYfKEh7KK0MYGmEUtukLjAoeQt6Ln iEq7RIPzjjh/syvnZik+he5fg6Wmj2Ltza0lDUG9QnyFRKbV40ta7RUy8A62IQVf9yFn kfJw== X-Gm-Message-State: AOUpUlGfOmuKyWEfJCu4BlIgwCFcp0oosgL8UEMRfrBQgeAR/LV6Lasz hhSo2ERLA8wdNoIdIGmo6aXQ95Er X-Google-Smtp-Source: AAOMgpe9LcvHoNZS+dXzI3lCAlLF5tAPlv4q6ZbXSPawapXmzyOtPPYVi5TI+opeuaT+vWw7h7mIcw== X-Received: by 2002:a63:6092:: with SMTP id u140-v6mr5440195pgb.433.1532174928087; Sat, 21 Jul 2018 05:08:48 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:06 +0530 Message-Id: <1532174832-21644-35-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 21 Jul 2018 12:08:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 21 Jul 2018 12:08:49 +0000 (UTC) for IP:'209.85.210.177' DOMAIN:'mail-pf1-f177.google.com' HELO:'mail-pf1-f177.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.311 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, SPF_PASS, T_DKIM_INVALID) 209.85.210.177 mail-pf1-f177.google.com 209.85.210.177 mail-pf1-f177.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 34/40] util: iptables: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 21 Jul 2018 12:10:02 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/viriptables.c | 52 +++++++++++++++++-----------------------------= ---- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/src/util/viriptables.c b/src/util/viriptables.c index e921954..e65e8dc 100644 --- a/src/util/viriptables.c +++ b/src/util/viriptables.c @@ -215,7 +215,7 @@ static char *iptablesFormatNetwork(virSocketAddr *netad= dr, unsigned int prefix) { virSocketAddr network; - char *netstr; + VIR_AUTOFREE(char *) netstr =3D NULL; char *ret; =20 if (!(VIR_SOCKET_ADDR_IS_FAMILY(netaddr, AF_INET) || @@ -238,7 +238,6 @@ static char *iptablesFormatNetwork(virSocketAddr *netad= dr, =20 ignore_value(virAsprintf(&ret, "%s/%d", netstr, prefix)); =20 - VIR_FREE(netstr); return ret; } =20 @@ -254,7 +253,7 @@ iptablesForwardAllowOut(virFirewallPtr fw, const char *physdev, int action) { - char *networkstr; + VIR_AUTOFREE(char *) networkstr =3D NULL; virFirewallLayer layer =3D VIR_SOCKET_ADDR_FAMILY(netaddr) =3D=3D AF_I= NET ? VIR_FIREWALL_LAYER_IPV4 : VIR_FIREWALL_LAYER_IPV6; =20 @@ -279,7 +278,6 @@ iptablesForwardAllowOut(virFirewallPtr fw, "--jump", "ACCEPT", NULL); =20 - VIR_FREE(networkstr); return 0; } =20 @@ -343,7 +341,7 @@ iptablesForwardAllowRelatedIn(virFirewallPtr fw, { virFirewallLayer layer =3D VIR_SOCKET_ADDR_FAMILY(netaddr) =3D=3D AF_I= NET ? VIR_FIREWALL_LAYER_IPV4 : VIR_FIREWALL_LAYER_IPV6; - char *networkstr; + VIR_AUTOFREE(char *) networkstr =3D NULL; =20 if (!(networkstr =3D iptablesFormatNetwork(netaddr, prefix))) return -1; @@ -370,7 +368,6 @@ iptablesForwardAllowRelatedIn(virFirewallPtr fw, "--jump", "ACCEPT", NULL); =20 - VIR_FREE(networkstr); return 0; } =20 @@ -432,7 +429,7 @@ iptablesForwardAllowIn(virFirewallPtr fw, { virFirewallLayer layer =3D VIR_SOCKET_ADDR_FAMILY(netaddr) =3D=3D AF_I= NET ? VIR_FIREWALL_LAYER_IPV4 : VIR_FIREWALL_LAYER_IPV6; - char *networkstr; + VIR_AUTOFREE(char *) networkstr =3D NULL; =20 if (!(networkstr =3D iptablesFormatNetwork(netaddr, prefix))) return -1; @@ -454,7 +451,6 @@ iptablesForwardAllowIn(virFirewallPtr fw, "--out-interface", iface, "--jump", "ACCEPT", NULL); - VIR_FREE(networkstr); return 0; } =20 @@ -661,12 +657,11 @@ iptablesForwardMasquerade(virFirewallPtr fw, const char *protocol, int action) { - int ret =3D -1; - char *networkstr =3D NULL; - char *addrStartStr =3D NULL; - char *addrEndStr =3D NULL; - char *portRangeStr =3D NULL; - char *natRangeStr =3D NULL; + VIR_AUTOFREE(char *) networkstr =3D NULL; + VIR_AUTOFREE(char *) addrStartStr =3D NULL; + VIR_AUTOFREE(char *) addrEndStr =3D NULL; + VIR_AUTOFREE(char *) portRangeStr =3D NULL; + VIR_AUTOFREE(char *) natRangeStr =3D NULL; virFirewallRulePtr rule; =20 if (!(networkstr =3D iptablesFormatNetwork(netaddr, prefix))) @@ -677,15 +672,15 @@ iptablesForwardMasquerade(virFirewallPtr fw, virReportError(VIR_ERR_INTERNAL_ERROR, _("Attempted to NAT '%s'. NAT is only supported for= IPv4."), networkstr); - goto cleanup; + return -1; } =20 if (VIR_SOCKET_ADDR_IS_FAMILY(&addr->start, AF_INET)) { if (!(addrStartStr =3D virSocketAddrFormat(&addr->start))) - goto cleanup; + return -1; if (VIR_SOCKET_ADDR_IS_FAMILY(&addr->end, AF_INET)) { if (!(addrEndStr =3D virSocketAddrFormat(&addr->end))) - goto cleanup; + return -1; } } =20 @@ -718,7 +713,7 @@ iptablesForwardMasquerade(virFirewallPtr fw, if (port->start < port->end && port->end < 65536) { if (virAsprintf(&portRangeStr, ":%u-%u", port->start, port->end) < 0) - goto cleanup; + return -1; } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid port range '%u-%u'."), @@ -739,7 +734,7 @@ iptablesForwardMasquerade(virFirewallPtr fw, } =20 if (r < 0) - goto cleanup; + return -1; =20 virFirewallRuleAddArgList(fw, rule, "--jump", "SNAT", @@ -753,14 +748,7 @@ iptablesForwardMasquerade(virFirewallPtr fw, "--to-ports", &portRangeStr[1], NULL= ); } =20 - ret =3D 0; - cleanup: - VIR_FREE(networkstr); - VIR_FREE(addrStartStr); - VIR_FREE(addrEndStr); - VIR_FREE(portRangeStr); - VIR_FREE(natRangeStr); - return ret; + return 0; } =20 /** @@ -827,8 +815,7 @@ iptablesForwardDontMasquerade(virFirewallPtr fw, const char *destaddr, int action) { - int ret =3D -1; - char *networkstr =3D NULL; + VIR_AUTOFREE(char *) networkstr =3D NULL; =20 if (!(networkstr =3D iptablesFormatNetwork(netaddr, prefix))) return -1; @@ -838,7 +825,7 @@ iptablesForwardDontMasquerade(virFirewallPtr fw, virReportError(VIR_ERR_INTERNAL_ERROR, _("Attempted to NAT '%s'. NAT is only supported for= IPv4."), networkstr); - goto cleanup; + return -1; } =20 if (physdev && physdev[0]) @@ -859,10 +846,7 @@ iptablesForwardDontMasquerade(virFirewallPtr fw, "--jump", "RETURN", NULL); =20 - ret =3D 0; - cleanup: - VIR_FREE(networkstr); - return ret; + return 0; } =20 /** --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175194432386.03305298397345; Sat, 21 Jul 2018 05:13:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3E5853082A2E; Sat, 21 Jul 2018 12:13:13 +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 0F588C4A64; Sat, 21 Jul 2018 12:13:13 +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 C2E444EE0C; Sat, 21 Jul 2018 12:13:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC985X016644 for ; Sat, 21 Jul 2018 08:09:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2FD7517AF9; Sat, 21 Jul 2018 12:09:08 +0000 (UTC) Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2638B5C20D for ; Sat, 21 Jul 2018 12:09:01 +0000 (UTC) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AB3B307D86F for ; Sat, 21 Jul 2018 12:08:50 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id n7-v6so8961679pgq.4 for ; Sat, 21 Jul 2018 05:08:50 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=NxV4LtzcmuolBAKQ1mrLvzYll5RuORNpf5orNy372Uo=; b=qVPW4gKverOLzt+69wL+O8m9v9CJDc6cO1CUSEJYc3UMpbXPsUm51RHEDm/zq5C5PD g4VpZvUUCpHtaFBCKKPZipv5bQCYKH9XQgpst9W5ipJ7gscqOXfV+xXeARgw2/rG0uAs g9zqVjzQINSinnqLwazNJeNcXwcUrNPbUwjq8QfT4LJJK+S0sfqwNhXG23eP16bEpSTb UT4hm+FMnG5t8P/8rA7HhDdVG+ptwEo31hDDGd+Ewr40fUu08Ocqmcft2VcUkIHRixRm A990u58uXWQL8uQ5zPzmMEq7LLZ4FemF3J85MVfjRm8pdF74pBjP8jXPx3jBpu6fycvW 6pFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=NxV4LtzcmuolBAKQ1mrLvzYll5RuORNpf5orNy372Uo=; b=mOvzgEwpg24Er+p2gQ0Kk86QtbTVf3XZmmvGgVbuR+tNLCm2h3YeOtZPOOfujqX/cn aX+XuH9yFP7ZcvjNAuHLpEMAyl/hXyfjSbt1BuIr+3stkuMblvw9gCdguXxF7gAHS1Zc tGnXtWzetAF+bcqjJIxwzE9/Ova4XBjgQ9DNJqtO+RmA+FOInG1DbJQe9lidNYFVEEsA YqueqmWo5nkfu+/Zrmi64F/GCUy+Gx+MFOdsJTiccz/0bdOu785HnUitDz7rXRzyFIUX 1jOq4pbylqk+x/jw1oy3OvhzZqES1xQc9sPfYbfUg9aBoffKFyxoJelAcCK9DVhJDyv5 nV1Q== X-Gm-Message-State: AOUpUlGkt3ctvoVMxDFXEXaqOFTvSJ5XqRo4bhflIPsHAjqTz3GQfQaE ktQNyCavX1YD1bUhUTSLkLP9puqS X-Google-Smtp-Source: AAOMgpclY0D/vJvj2LdZZgIrQ3tQBimsBq2t7kbnG/Sn60IDT8hWDeIdZTsY9n1uGEpYkMag+mNf4g== X-Received: by 2002:a63:4506:: with SMTP id s6-v6mr5610594pga.422.1532174929879; Sat, 21 Jul 2018 05:08:49 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:07 +0530 Message-Id: <1532174832-21644-36-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 21 Jul 2018 12:08:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Sat, 21 Jul 2018 12:08:50 +0000 (UTC) for IP:'209.85.215.174' DOMAIN:'mail-pg1-f174.google.com' HELO:'mail-pg1-f174.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.174 mail-pg1-f174.google.com 209.85.215.174 mail-pg1-f174.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 35/40] util: iscsi: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 21 Jul 2018 12:13:13 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/viriscsi.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index d4c745a..13fd02c 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -80,7 +80,7 @@ virISCSIGetSession(const char *devpath, .session =3D NULL, .devpath =3D devpath, }; - char *error =3D NULL; + VIR_AUTOFREE(char *) error =3D NULL; int exitstatus =3D 0; =20 virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", @@ -101,7 +101,6 @@ virISCSIGetSession(const char *devpath, NULLSTR(error)); =20 cleanup: - VIR_FREE(error); virCommandFree(cmd); return cbdata.session; } @@ -120,7 +119,10 @@ virStorageBackendIQNFound(const char *initiatoriqn, int ret =3D IQN_MISSING, fd =3D -1; char ebuf[64]; FILE *fp =3D NULL; - char *line =3D NULL, *newline =3D NULL, *iqn =3D NULL, *token =3D NULL; + VIR_AUTOFREE(char *) line =3D NULL; + char *newline =3D NULL; + char *iqn =3D NULL; + char *token =3D NULL; virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "iface", NULL); =20 @@ -192,7 +194,6 @@ virStorageBackendIQNFound(const char *initiatoriqn, if (ret =3D=3D IQN_MISSING) VIR_DEBUG("Could not find interface with IQN '%s'", iqn); =20 - VIR_FREE(line); VIR_FORCE_FCLOSE(fp); VIR_FORCE_CLOSE(fd); virCommandFree(cmd); @@ -206,7 +207,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, char **ifacename) { int ret =3D -1, exitstatus =3D -1; - char *temp_ifacename; + VIR_AUTOFREE(char *) temp_ifacename =3D NULL; virCommandPtr cmd =3D NULL; =20 if (virAsprintf(&temp_ifacename, @@ -267,7 +268,6 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, =20 cleanup: virCommandFree(cmd); - VIR_FREE(temp_ifacename); if (ret !=3D 0) VIR_FREE(*ifacename); return ret; @@ -289,7 +289,7 @@ virISCSIConnection(const char *portal, NULL }; virCommandPtr cmd; - char *ifacename =3D NULL; + VIR_AUTOFREE(char *) ifacename =3D NULL; =20 cmd =3D virCommandNewArgs(baseargv); virCommandAddArgSet(cmd, extraargv); @@ -326,7 +326,6 @@ virISCSIConnection(const char *portal, =20 cleanup: virCommandFree(cmd); - VIR_FREE(ifacename); =20 return ret; } @@ -377,15 +376,13 @@ virISCSIGetTargets(char **const groups, void *data) { struct virISCSITargetList *list =3D data; - char *target; + VIR_AUTOFREE(char *) target =3D NULL; =20 if (VIR_STRDUP(target, groups[1]) < 0) return -1; =20 - if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0) { - VIR_FREE(target); + if (VIR_APPEND_ELEMENT(list->targets, list->ntargets, target) < 0) return -1; - } =20 return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175171418973.2398028185975; Sat, 21 Jul 2018 05:12:51 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 823B63084049; Sat, 21 Jul 2018 12:12: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 4AD075E1CD; Sat, 21 Jul 2018 12:12: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 EF1D24EE13; Sat, 21 Jul 2018 12:12:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC98wK016643 for ; Sat, 21 Jul 2018 08:09:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 286414C7; Sat, 21 Jul 2018 12:09:08 +0000 (UTC) Received: from mx1.redhat.com (ext-mx11.extmail.prod.ext.phx2.redhat.com [10.5.110.40]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1CC385E1CD for ; Sat, 21 Jul 2018 12:09:04 +0000 (UTC) Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A99DB3084041 for ; Sat, 21 Jul 2018 12:08:52 +0000 (UTC) Received: by mail-pg1-f180.google.com with SMTP id y5-v6so8983012pgv.1 for ; Sat, 21 Jul 2018 05:08:52 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=/JUNmhgNyHWhe1NZnhQthSkYMlMfEuw0tdhTNvhMCRw=; b=XVT8PCZk1r9rQOxO3UA2T7mh/kjNTKoGGl02BGtDYQXc1jocALBcII0z6/K1Nzye67 6uY/E0wh7+hIaBYVrbS3Uymyi8/dfRv27rm6Hkq2ULMM2Bdo3DpAaPf/UmmGo0uTwZWF sZUPmYyZZgZb+9nYblx4O/G0QmGYujgMxpqzumRgLtJQKJk4LzutrWYvsivdH4j0M4m5 HtUc8gxfN50U+/1kXYrmnLCf9Ggrrx6WIIucjpjQVRPSIkbigdpwhVZjx0j7kFLT36x9 1bKd+ZH+6p+LpNiwgpoyEwtQwB0QpTSz0deI2C1GL1nV7xCfSFa3+Rbm5wbpKp+Mk7Ys HoHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=/JUNmhgNyHWhe1NZnhQthSkYMlMfEuw0tdhTNvhMCRw=; b=jLWDziSEj/bVXfHOtK9U1rkNmecTcxApSVJ4yxHqFJ7SAmh+ZztnYiun7OaGnCLdSx oBgIiPBIEkMalWJyF9DWN8gzma501vHPUWRim1uAa4A21jQSQ+Ve81SmadtFGCc6Bx8W RWC6QR8xt5feSAXJXN3u2//canYvSWuribULobn4fTykyfJspsHK4iG5LM5FpIPWBVas IyCQ34EmP6fKzZBABUR0sM+CR5tWXtFCh/rebtJ4fYCATMS+byvaOXoOpcboqlNBUNQy NyNfD1ASntRdjsgajIW1WKxDRkQuONQq0TRr66euUTdp3oOuHxPUM3NPBdQZzIw7hWlt QpQQ== X-Gm-Message-State: AOUpUlHjo/52M4cAozwlC0qrlc33tR19NyZxZB6e9V3/ircGflT3Pi7d mhwULIQczAcNeV5PeAQh8jvg86Oz X-Google-Smtp-Source: AAOMgpd0X0AXZVEYCH+iEXWlovu3esuXSJoQcKX3GoEQC3wr/s1HrqGeTx8plwW2MiachQ6Byru66g== X-Received: by 2002:a63:d518:: with SMTP id c24-v6mr5472876pgg.357.1532174931981; Sat, 21 Jul 2018 05:08:51 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:08 +0530 Message-Id: <1532174832-21644-37-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sat, 21 Jul 2018 12:08:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sat, 21 Jul 2018 12:08:52 +0000 (UTC) for IP:'209.85.215.180' DOMAIN:'mail-pg1-f180.google.com' HELO:'mail-pg1-f180.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.301 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.215.180 mail-pg1-f180.google.com 209.85.215.180 mail-pg1-f180.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 36/40] util: iscsi: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Sat, 21 Jul 2018 12:12:50 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/viriscsi.c | 68 +++++++++++++++++--------------------------------= ---- 1 file changed, 22 insertions(+), 46 deletions(-) diff --git a/src/util/viriscsi.c b/src/util/viriscsi.c index 13fd02c..a3367bc 100644 --- a/src/util/viriscsi.c +++ b/src/util/viriscsi.c @@ -83,7 +83,7 @@ virISCSIGetSession(const char *devpath, VIR_AUTOFREE(char *) error =3D NULL; int exitstatus =3D 0; =20 - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, "--mode", + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode= ", "session", NULL); virCommandSetErrorBuffer(cmd, &error); =20 @@ -93,15 +93,13 @@ virISCSIGetSession(const char *devpath, vars, virISCSIExtractSession, &cbdata, NULL, &exitstatus) < 0) - goto cleanup; + return cbdata.session; =20 if (cbdata.session =3D=3D NULL && !probe) virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find iscsiadm session: %s"), NULLSTR(error)); =20 - cleanup: - virCommandFree(cmd); return cbdata.session; } =20 @@ -123,7 +121,7 @@ virStorageBackendIQNFound(const char *initiatoriqn, char *newline =3D NULL; char *iqn =3D NULL; char *token =3D NULL; - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "iface", NULL); =20 if (VIR_ALLOC_N(line, LINE_SIZE) !=3D 0) { @@ -196,7 +194,6 @@ virStorageBackendIQNFound(const char *initiatoriqn, =20 VIR_FORCE_FCLOSE(fp); VIR_FORCE_CLOSE(fd); - virCommandFree(cmd); =20 return ret; } @@ -208,7 +205,7 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, { int ret =3D -1, exitstatus =3D -1; VIR_AUTOFREE(char *) temp_ifacename =3D NULL; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 if (virAsprintf(&temp_ifacename, "libvirt-iface-%08llx", @@ -267,7 +264,6 @@ virStorageBackendCreateIfaceIQN(const char *initiatoriq= n, ret =3D 0; =20 cleanup: - virCommandFree(cmd); if (ret !=3D 0) VIR_FREE(*ifacename); return ret; @@ -280,7 +276,6 @@ virISCSIConnection(const char *portal, const char *target, const char **extraargv) { - int ret =3D -1; const char *const baseargv[] =3D { ISCSIADM, "--mode", "node", @@ -288,7 +283,7 @@ virISCSIConnection(const char *portal, "--targetname", target, NULL }; - virCommandPtr cmd; + VIR_AUTOPTR(virCommand) cmd =3D NULL; VIR_AUTOFREE(char *) ifacename =3D NULL; =20 cmd =3D virCommandNewArgs(baseargv); @@ -301,7 +296,7 @@ virISCSIConnection(const char *portal, break; case IQN_MISSING: if (virStorageBackendCreateIfaceIQN(initiatoriqn, &ifacename) = !=3D 0) - goto cleanup; + return -1; /* * iscsiadm doesn't let you send commands to the Interface IQN, * unless you've first issued a 'sendtargets' command to the @@ -309,25 +304,20 @@ virISCSIConnection(const char *portal, * "iscsiadm: No records found" */ if (virISCSIScanTargets(portal, NULL, NULL) < 0) - goto cleanup; + return -1; =20 break; case IQN_ERROR: default: - goto cleanup; + return -1; } virCommandAddArgList(cmd, "--interface", ifacename, NULL); } =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - - return ret; + return 0; } =20 =20 @@ -354,14 +344,12 @@ virISCSIConnectionLogout(const char *portal, int virISCSIRescanLUNs(const char *session) { - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "session", "-r", session, "-R", NULL); - int ret =3D virCommandRun(cmd, NULL); - virCommandFree(cmd); - return ret; + return virCommandRun(cmd, NULL); } =20 =20 @@ -409,8 +397,7 @@ virISCSIScanTargets(const char *portal, int vars[] =3D { 2 }; struct virISCSITargetList list; size_t i; - int ret =3D -1; - virCommandPtr cmd =3D virCommandNewArgList(ISCSIADM, + VIR_AUTOPTR(virCommand) cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "discovery", "--type", "sendtargets", "--portal", portal, @@ -425,7 +412,7 @@ virISCSIScanTargets(const char *portal, vars, virISCSIGetTargets, &list, NULL, NULL) < 0) - goto cleanup; + return -1; =20 if (ntargetsret && targetsret) { *ntargetsret =3D list.ntargets; @@ -436,10 +423,7 @@ virISCSIScanTargets(const char *portal, VIR_FREE(list.targets); } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /* @@ -462,9 +446,8 @@ int virISCSINodeNew(const char *portal, const char *target) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; int status; - int ret =3D -1; =20 cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "node", @@ -477,20 +460,17 @@ virISCSINodeNew(const char *portal, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed new node mode for target '%s'"), target); - goto cleanup; + return -1; } =20 if (status !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("%s failed new mode for target '%s' with status '= %d'"), ISCSIADM, target, status); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 =20 @@ -500,9 +480,8 @@ virISCSINodeUpdate(const char *portal, const char *name, const char *value) { - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; int status; - int ret =3D -1; =20 cmd =3D virCommandNewArgList(ISCSIADM, "--mode", "node", @@ -518,11 +497,8 @@ virISCSINodeUpdate(const char *portal, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to update '%s' of node mode for target '%= s'"), name, target); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - virCommandFree(cmd); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153217521768843.21022703411086; Sat, 21 Jul 2018 05:13:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5B39F85A02; Sat, 21 Jul 2018 12:13:36 +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 1B93C60BE7; Sat, 21 Jul 2018 12:13:36 +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 B56551841C4A; Sat, 21 Jul 2018 12:13:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC9BtC016669 for ; Sat, 21 Jul 2018 08:09:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9932D308BDB7; Sat, 21 Jul 2018 12:09:11 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8FDCC308BDAE for ; Sat, 21 Jul 2018 12:09:05 +0000 (UTC) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C9CE2308123F for ; Sat, 21 Jul 2018 12:08:54 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id x5-v6so8960425pgp.7 for ; Sat, 21 Jul 2018 05:08:54 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.52 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=muRH6bQndyUyTc10d5BzMHJlxY9uD76s4B1pyR4QuHE=; b=HWmXdB2+qqfOHDTfhE8Ogh/bM3rg4DITYxmAtIzLQSdKy6ygu4R/z8dSi7OfR8OMZL xElYw10nVkRNM6V9oTTDoek3I0DmKehGhqkk0DDW0sdXSCIERM8Doweg1Of7LeQlTVUy bVoqv+XBLzw9N4NPcTxOmVGQiY7eTu6LxONvK+a5y4M4O7yAUf0CLF7HzIdKTUEw6taL CXPA4VEl3E71F1+98He2JNRU+PpXx55eQJvHK9LEn2MhqN8MbHMDv6GOuYAdG3DZYXb4 miEQrR+5plxYv42C77PhqTmaFRYENsmhXoqQM78IVAXTK0D4wii4/cJXS98s96hEmrNm 3ikg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=muRH6bQndyUyTc10d5BzMHJlxY9uD76s4B1pyR4QuHE=; b=k99GVlXbbsUse6t7DmTc9xm2zIk2NyXL3dBYSZkTVslud12b93j7qfUGQgeiHC/5Z6 adQ1UAdpjCiWEfxjrRrx07hnyVq6pbgx4VwTJS57LYw6xL4aeSLGuikaUYHTBw7TyF7L jOxcqPvwXrQy4yY49LibEM+hqk++NCTpiIZExpPbVNwa5crC/2dcevZ00rj3O26imhlj VAU+BNttZFeHQ4/qsYBgBVNJB78JB+rzZqYKog18/Nmc0heMmJBCbqEWggz2qP5vaPat D+OTBUmCaXkY6B9BohrBGz7d1bHMPx4+kaWP+5+m1FZngzdKQ5iTYTkAak9asfUqdjQP cDLQ== X-Gm-Message-State: AOUpUlHCIq94dlc9bzi0zD3Xp9idHbR8eJ/RLuaJ0/3hh2DIGgmZ4lJH /YJr01/DtZnwI9yRMRbd4ICqXKm/ X-Google-Smtp-Source: AAOMgpccdP7TuV35YYSdEEJmglAruW7K8NAM+jWBsC9Ufs7qLspXqZt8h+5vivcgCHetG6etDdyo/g== X-Received: by 2002:a63:121a:: with SMTP id h26-v6mr5565607pgl.316.1532174934147; Sat, 21 Jul 2018 05:08:54 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:09 +0530 Message-Id: <1532174832-21644-38-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 21 Jul 2018 12:08:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 21 Jul 2018 12:08:54 +0000 (UTC) for IP:'209.85.215.195' DOMAIN:'mail-pg1-f195.google.com' HELO:'mail-pg1-f195.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.195 mail-pg1-f195.google.com 209.85.215.195 mail-pg1-f195.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 37/40] util: kmod: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Sat, 21 Jul 2018 12:13:36 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virkmod.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/util/virkmod.c b/src/util/virkmod.c index 219fad6..d981cd4 100644 --- a/src/util/virkmod.c +++ b/src/util/virkmod.c @@ -155,13 +155,12 @@ virKModUnload(const char *module) bool virKModIsBlacklisted(const char *module) { - bool retval =3D false; size_t i; - char *drvblklst =3D NULL; - char *outbuf =3D NULL; + VIR_AUTOFREE(char *) drvblklst =3D NULL; + VIR_AUTOFREE(char *) outbuf =3D NULL; =20 if (virAsprintfQuiet(&drvblklst, "blacklist %s\n", module) < 0) - goto cleanup; + return false; =20 /* modprobe will convert all '-' into '_', so we need to as well */ for (i =3D 0; i < drvblklst[i]; i++) @@ -169,13 +168,10 @@ virKModIsBlacklisted(const char *module) drvblklst[i] =3D '_'; =20 if (doModprobe("-c", NULL, &outbuf, NULL) < 0) - goto cleanup; + return false; =20 if (strstr(outbuf, drvblklst)) - retval =3D true; + return true; =20 - cleanup: - VIR_FREE(drvblklst); - VIR_FREE(outbuf); - return retval; + return false; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175320629707.4054184745535; Sat, 21 Jul 2018 05:15:20 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 58D72C04B948; Sat, 21 Jul 2018 12:15:19 +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 210EC5E1CD; Sat, 21 Jul 2018 12:15:19 +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 CB3681841C4B; Sat, 21 Jul 2018 12:15:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC9Nkj016791 for ; Sat, 21 Jul 2018 08:09:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAC8260175; Sat, 21 Jul 2018 12:09:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B29C060172 for ; Sat, 21 Jul 2018 12:09:08 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3EC895D687 for ; Sat, 21 Jul 2018 12:08:57 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id s7-v6so5535866pgv.3 for ; Sat, 21 Jul 2018 05:08:57 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=tBcNqeHQMjvekw84XTkMhCBGPq0Vn8Z/YJ81rHevDu0=; b=FNX2gu5u/BblqKYiJAhqLRr2Oa9LjPf0yguB/UQjr/6NFERZf5owVvmdlhmIHkQIZH C93jYNEeHr3AJuzuhGRfKXlr1rXCD/SOrw/KdB/u2iGDXehUrDL3bz1UZjbygceNdHhc 4UnLE8ClDko/N0HfuQQDi0X+bS+8yB0C51ZOZiW7GjI3zWMjpYziTmwiHfCvX67SYucG diS7yP30q1WtSrcWgDt4pqdTBww2XEZ2qzCnJrwFUAvEHovRVAEr7FnqXwi1aQexPRYp cOif7Hy8vuPsgADiNucBR61OvBvYNrjJNBdo+4MA1UDc6qQYOcGYCZBWjO86ggua/ygf tn4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=tBcNqeHQMjvekw84XTkMhCBGPq0Vn8Z/YJ81rHevDu0=; b=fTQo7V+MGcxp3qP1rYRXBA4E6KrT5ZEZ7/mH6lEVywDJKhMUQNdOd23qs66ocLrba1 JgRih9pOg0icpqqS1MMhgmoUTXhjz9iliqhmvuY5Ywp2bjuu/rjzOJZZFILl1aLGVedP 3WAUAigF1lP0lBUsL9XunSDxxYj2mSzj/huXzPouoan/S42oYjOXPXXLGCfh7j2y09g/ +zl2I+HuYT54Eg/0QvzecKfVwbTQj8r+wHgSq6i5uzxVyRVGpvIRNgjWovPQ72eim8vq 4LNbau1yoWykQnGB+R9ilPO8V/Gm654hSeuC/X9EaRj021sQELbzVM8DEe4VBfsLEtCF m+vg== X-Gm-Message-State: AOUpUlEUNPPJiHHp6KJyl7caPMbHR4EQ4wNwvPy1RXx/bPa7U3ige5Iy qgO5FS9vdDfwjGN11BwhCtymwLYF X-Google-Smtp-Source: AAOMgpdz25wG7XRU+1BbK+rB97Sx8tXtOhKEEK4HEGHK+Jc6IwT9PfQgve4qt16vKPUc7I3tFN2bPw== X-Received: by 2002:a63:d80f:: with SMTP id b15-v6mr5501904pgh.347.1532174936516; Sat, 21 Jul 2018 05:08:56 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:10 +0530 Message-Id: <1532174832-21644-39-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 21 Jul 2018 12:08:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 21 Jul 2018 12:08:57 +0000 (UTC) for IP:'209.85.215.194' DOMAIN:'mail-pg1-f194.google.com' HELO:'mail-pg1-f194.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.215.194 mail-pg1-f194.google.com 209.85.215.194 mail-pg1-f194.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 38/40] util: kmod: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 21 Jul 2018 12:15:19 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virkmod.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/util/virkmod.c b/src/util/virkmod.c index d981cd4..9d0375b 100644 --- a/src/util/virkmod.c +++ b/src/util/virkmod.c @@ -28,8 +28,7 @@ static int doModprobe(const char *opts, const char *module, char **outbuf, char **err= buf) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNew(MODPROBE); if (opts) @@ -42,32 +41,23 @@ doModprobe(const char *opts, const char *module, char *= *outbuf, char **errbuf) virCommandSetErrorBuffer(cmd, errbuf); =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 static int doRmmod(const char *module, char **errbuf) { - int ret =3D -1; - virCommandPtr cmd =3D NULL; + VIR_AUTOPTR(virCommand) cmd =3D NULL; =20 cmd =3D virCommandNewArgList(RMMOD, module, NULL); virCommandSetErrorBuffer(cmd, errbuf); =20 if (virCommandRun(cmd, NULL) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; - - cleanup: - virCommandFree(cmd); - return ret; + return 0; } =20 /** --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175051985226.93827662046817; Sat, 21 Jul 2018 05:10:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E118A3082152; Sat, 21 Jul 2018 12:10: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 A8284600C7; Sat, 21 Jul 2018 12:10:47 +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 5B8611841C6E; Sat, 21 Jul 2018 12:10:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC9VsD016827 for ; Sat, 21 Jul 2018 08:09:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id E33385B680; Sat, 21 Jul 2018 12:09:31 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB0A65B686 for ; Sat, 21 Jul 2018 12:09:10 +0000 (UTC) Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 074A03081252 for ; Sat, 21 Jul 2018 12:09:00 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id e13-v6so223491pff.7 for ; Sat, 21 Jul 2018 05:08:59 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=+S2HIATW0FYgQX2+zQWQ+/AFQQ2aCfZHBfDgE/IGu9s=; b=i7kwz8ed+X4XcQmnzQeqzHsMwueoyLq4DkoHhIXLot68P1Ke/YCz0yMp1jzcab88D0 FHGsG6dC0hKl+uM8frXRNptGitLYCsCs0ivhiZ0Ssss+W9jNunIxn3l8pYwmnkcEvd3g lQLV2+pjrjmQszJD/uVzYQ3RStJ2KU3SCDmCPr8bIj12AWxa15FFwzK+0UfFqlW1Vva0 bqpOnp+fXLMHSX48+6oUXGQTRhHrHls/ZxCt/8kOoSpW8GwXJfv5yzs3Cdo0N2F+Y/IQ fFzw8k3cVmnRzBVRKDvcfifZxbfZ9LsrQ95SaLDAGdWqJ3dSeEF4/RwBXP2s4HqTVnBR 28Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+S2HIATW0FYgQX2+zQWQ+/AFQQ2aCfZHBfDgE/IGu9s=; b=pZjqEfpZNYDQEBPGZXz8/9ockLC8ggYRvpFd8oR/RjO6TSahak6N2DWJn2Rb0KYkyk JzkKOVHzob+Z+3Q+SJKVbCXBqhNIfd+VWoLdYFqOt0pwB/RzdHHStN38W0zo5zD7lfQM vWWWyHV6fDB3Q2HK7pYa2NNGesczsFLPXV4Yr5Q6mk0Aq1cgIbrSUAi0XklUepk9+REr 4oywgZDBZj4sqA4h5IeQxcQhNevTDMI4NPE2cvpBW5pbRGhS75V/nHd+nz7MROkYaB8+ cDAt+J+K4oi/wbVJDV9Xwz8Dmv6LVjZ6oj3wJQVTHUgyaoSz57mqe/97ARVu+KOUCmhs tV5Q== X-Gm-Message-State: AOUpUlF5At0fRijodFgwOCZWGMCWj+NHb/KaVl+vWDtJ3ro5IikiqMKu 3N1vRnWKodluZblUuczSeQuB4Ptd X-Google-Smtp-Source: AAOMgpe0w1OkRwmED3FUz8MiNp92VQh51zpZgBVMsOd0yoxAMvph7Vgh56O7KmtZsDwDaQY05Bvb0Q== X-Received: by 2002:a63:e145:: with SMTP id h5-v6mr5354405pgk.286.1532174939252; Sat, 21 Jul 2018 05:08:59 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:11 +0530 Message-Id: <1532174832-21644-40-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 21 Jul 2018 12:09:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Sat, 21 Jul 2018 12:09:00 +0000 (UTC) for IP:'209.85.210.196' DOMAIN:'mail-pf1-f196.google.com' HELO:'mail-pf1-f196.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.311 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, SPF_PASS, T_DKIM_INVALID) 209.85.210.196 mail-pf1-f196.google.com 209.85.210.196 mail-pf1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 39/40] util: lease: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 21 Jul 2018 12:10:51 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virlease.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util/virlease.c b/src/util/virlease.c index b49105d..baaceaf 100644 --- a/src/util/virlease.c +++ b/src/util/virlease.c @@ -55,7 +55,7 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_array_= new, const char *ip_to_delete, char **server_duid) { - char *lease_entries =3D NULL; + VIR_AUTOFREE(char *) lease_entries =3D NULL; virJSONValuePtr leases_array =3D NULL; long long expirytime; int custom_lease_file_len =3D 0; @@ -146,7 +146,6 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_arra= y_new, =20 cleanup: virJSONValueFree(leases_array); - VIR_FREE(lease_entries); return ret; } =20 @@ -235,7 +234,7 @@ virLeaseNew(virJSONValuePtr *lease_ret, virJSONValuePtr lease_new =3D NULL; const char *exptime_tmp =3D virGetEnvAllowSUID("DNSMASQ_LEASE_EXPIRES"= ); long long expirytime =3D 0; - char *exptime =3D NULL; + VIR_AUTOFREE(char *) exptime =3D NULL; int ret =3D -1; =20 /* In case hostname is still unknown, use the last known one */ @@ -291,7 +290,6 @@ virLeaseNew(virJSONValuePtr *lease_ret, *lease_ret =3D lease_new; lease_new =3D NULL; cleanup: - VIR_FREE(exptime); virJSONValueFree(lease_new); return ret; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 08:13:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532175129035886.8322445137284; Sat, 21 Jul 2018 05:12:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFC0A3082155; Sat, 21 Jul 2018 12:12:02 +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 9C320300165E; Sat, 21 Jul 2018 12:12:01 +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 591071841C5C; Sat, 21 Jul 2018 12:12:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC9Q1n016802 for ; Sat, 21 Jul 2018 08:09:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id E8A895B682; Sat, 21 Jul 2018 12:09:26 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E04DD5B680 for ; Sat, 21 Jul 2018 12:09:13 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D989081108 for ; Sat, 21 Jul 2018 12:09:01 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id w3-v6so6301825plq.2 for ; Sat, 21 Jul 2018 05:09:01 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.59 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=JRDYBIiuzR4gzwAomd1iytcNa9gu27S8yqD5P0Q5FuU=; b=QnEzx7Gi6UfZksv/CQKgCau/reX/9Egga0J5NfDiIQGDLmkceLbZxSvSy0aZasZ99p HYFTQHv6ZRxvhGrtB+2CXAI9iWdw9hniXrZF3huMuk3xNTEdAHbS5exqVx+KiT2x3aLc e/ybOqN2crZ6LBtraXOGlbzlJqheMRZ8xfe3ausHWhYYvZCQAgSbv36uczzDLTHR98c3 rYz81KkV95VpK9D5EGOj50bjbb9i+3YHpDOtPJtg4ySytzNdYGx8c8QAAuCmuFMzvvAf vdWpC1LhnsjiswHonuuDJo53TrJCSx4iUSA+goqagehfw148FJO3kY/uxi8SrYcdIRIm cB8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=JRDYBIiuzR4gzwAomd1iytcNa9gu27S8yqD5P0Q5FuU=; b=F4HN1IlDujhqDdOwhoM7V7+/c0Kdxz8AasBlrvsjTZNFb1EHIvV1syIBRTe6NQDCvK HAOt3kfOYl6QdnZmsDQiz3Oe985RuMwBEos30RwgOVXprHeZYP4TvNbLjrjlxW0Ndi2J 4VlOVO9I29SB0yKcJ7/Z84zbi+6k95/TbbOtoYbKmnbrfzS70b3w0O35wmz/OelLgEjv EWoLhy9ZRbmu/HX0+tCVOv91HXi5f/DEwkzPxL6eUDzIQtjE22hG41LTU/188rIa1Fb9 AoMTwL93gA3UTBKtFUkUhTvXUL9pCGId84n/0HAzAiOw9+zeQS9bpbGt4AwZazKIVWJr rRPw== X-Gm-Message-State: AOUpUlEugUIcW3IpjE4XdpqEaShQaT78H70AoLeZ0nQNq1R3Lct/kvwr ffpiyNgrjC7Klhwh3wOUmQKYiM17 X-Google-Smtp-Source: AAOMgpdtcpDv1HLdHj25nMH5uhYrGidXPH519kyDK5Qx0O2iNEvPIziw0davA2Wkul6t/cM1UWeLHw== X-Received: by 2002:a17:902:280b:: with SMTP id e11-v6mr5645760plb.298.1532174941152; Sat, 21 Jul 2018 05:09:01 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:12 +0530 Message-Id: <1532174832-21644-41-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 21 Jul 2018 12:09:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 21 Jul 2018 12:09:02 +0000 (UTC) for IP:'209.85.160.68' DOMAIN:'mail-pl0-f68.google.com' HELO:'mail-pl0-f68.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 40/40] util: lease: use VIR_AUTOPTR for aggregate types 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Sat, 21 Jul 2018 12:12:08 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virlease.c | 76 ++++++++++++++++++++-----------------------------= ---- 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/src/util/virlease.c b/src/util/virlease.c index baaceaf..7c6c37e 100644 --- a/src/util/virlease.c +++ b/src/util/virlease.c @@ -56,40 +56,36 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_arra= y_new, char **server_duid) { VIR_AUTOFREE(char *) lease_entries =3D NULL; - virJSONValuePtr leases_array =3D NULL; + VIR_AUTOPTR(virJSONValue) leases_array =3D NULL; long long expirytime; int custom_lease_file_len =3D 0; virJSONValuePtr lease_tmp =3D NULL; const char *ip_tmp =3D NULL; const char *server_duid_tmp =3D NULL; size_t i; - int ret =3D -1; =20 /* Read entire contents */ if ((custom_lease_file_len =3D virFileReadAll(custom_lease_file, VIR_NETWORK_DHCP_LEASE_FIL= E_SIZE_MAX, &lease_entries)) < 0) { - goto cleanup; + return -1; } =20 /* Check for previous leases */ - if (custom_lease_file_len =3D=3D 0) { - ret =3D 0; - goto cleanup; - } + if (custom_lease_file_len =3D=3D 0) + return 0; =20 if (!(leases_array =3D virJSONValueFromString(lease_entries))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid json in file: %s, rewriting it"), custom_lease_file); - ret =3D 0; - goto cleanup; + return 0; } =20 if (!virJSONValueIsArray(leases_array)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("couldn't fetch array of leases")); - goto cleanup; + return -1; } =20 i =3D 0; @@ -97,14 +93,14 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_arra= y_new, if (!(lease_tmp =3D virJSONValueArrayGet(leases_array, i))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to parse json")); - goto cleanup; + return -1; } =20 if (!(ip_tmp =3D virJSONValueObjectGetString(lease_tmp, "ip-addres= s")) || (virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", &ex= pirytime) < 0)) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to parse json")); - goto cleanup; + return -1; } =20 /* Check whether lease has to be included or not */ @@ -121,14 +117,14 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_ar= ray_new, /* Control reaches here when the 'action' is not for an * ipv6 lease or, for some weird reason the env var * DNSMASQ_SERVER_DUID wasn't set*/ - goto cleanup; + return -1; } } else { /* Inject server-duid into those ipv6 leases which * didn't have it previously, for example, those * created by leaseshelper from libvirt 1.2.6 */ if (virJSONValueObjectAppendString(lease_tmp, "server-duid= ", *server_duid) < 0) - goto cleanup; + return -1; } } =20 @@ -136,17 +132,13 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_ar= ray_new, if (virJSONValueArrayAppend(leases_array_new, lease_tmp) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create json")); - goto cleanup; + return -1; } =20 ignore_value(virJSONValueArraySteal(leases_array, i)); } =20 - ret =3D 0; - - cleanup: - virJSONValueFree(leases_array); - return ret; + return 0; } =20 =20 @@ -157,7 +149,6 @@ virLeasePrintLeases(virJSONValuePtr leases_array_new, virJSONValuePtr lease_tmp =3D NULL; const char *ip_tmp =3D NULL; long long expirytime =3D 0; - int ret =3D -1; size_t i; =20 /* Man page of dnsmasq says: the script (helper program, in our case) @@ -174,7 +165,7 @@ virLeasePrintLeases(virJSONValuePtr leases_array_new, if (!(ip_tmp =3D virJSONValueObjectGetString(lease_tmp, "ip-addres= s"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to parse json")); - goto cleanup; + return -1; } if (!strchr(ip_tmp, ':')) { if (virJSONValueObjectGetNumberLong(lease_tmp, "expiry-time", @@ -198,7 +189,7 @@ virLeasePrintLeases(virJSONValuePtr leases_array_new, if (!(ip_tmp =3D virJSONValueObjectGetString(lease_tmp, "ip-ad= dress"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to parse json")); - goto cleanup; + return -1; } if (strchr(ip_tmp, ':')) { if (virJSONValueObjectGetNumberLong(lease_tmp, "expiry-tim= e", @@ -215,10 +206,7 @@ virLeasePrintLeases(virJSONValuePtr leases_array_new, } } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 =20 @@ -231,24 +219,21 @@ virLeaseNew(virJSONValuePtr *lease_ret, const char *iaid, const char *server_duid) { - virJSONValuePtr lease_new =3D NULL; + VIR_AUTOPTR(virJSONValue) lease_new =3D NULL; const char *exptime_tmp =3D virGetEnvAllowSUID("DNSMASQ_LEASE_EXPIRES"= ); long long expirytime =3D 0; VIR_AUTOFREE(char *) exptime =3D NULL; - int ret =3D -1; =20 /* In case hostname is still unknown, use the last known one */ if (!hostname) hostname =3D virGetEnvAllowSUID("DNSMASQ_OLD_HOSTNAME"); =20 - if (!mac) { - ret =3D 0; - goto cleanup; - } + if (!mac) + return 0; =20 if (exptime_tmp) { if (VIR_STRDUP(exptime, exptime_tmp) < 0) - goto cleanup; + return -1; =20 /* Removed extraneous trailing space in DNSMASQ_LEASE_EXPIRES * (dnsmasq < 2.52) */ @@ -261,35 +246,32 @@ virLeaseNew(virJSONValuePtr *lease_ret, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to convert lease expiry time to long long= : %s"), NULLSTR(exptime)); - goto cleanup; + return -1; } =20 /* Create new lease */ if (!(lease_new =3D virJSONValueNewObject())) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to create json")); - goto cleanup; + return -1; } =20 if (iaid && virJSONValueObjectAppendString(lease_new, "iaid", iaid) < = 0) - goto cleanup; + return -1; if (ip && virJSONValueObjectAppendString(lease_new, "ip-address", ip) = < 0) - goto cleanup; + return -1; if (mac && virJSONValueObjectAppendString(lease_new, "mac-address", ma= c) < 0) - goto cleanup; + return -1; if (hostname && virJSONValueObjectAppendString(lease_new, "hostname", = hostname) < 0) - goto cleanup; + return -1; if (clientid && virJSONValueObjectAppendString(lease_new, "client-id",= clientid) < 0) - goto cleanup; + return -1; if (server_duid && virJSONValueObjectAppendString(lease_new, "server-d= uid", server_duid) < 0) - goto cleanup; + return -1; if (expirytime && virJSONValueObjectAppendNumberLong(lease_new, "expir= y-time", expirytime) < 0) - goto cleanup; + return -1; =20 - ret =3D 0; *lease_ret =3D lease_new; lease_new =3D NULL; - cleanup: - virJSONValueFree(lease_new); - return ret; + return 0; } --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list