From nobody Wed May 14 01:26:41 2025 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 1528124111581738.66229609376; Mon, 4 Jun 2018 07:55:11 -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 654EF30A78DA; Mon, 4 Jun 2018 14:55:09 +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 10D89308BDB1; Mon, 4 Jun 2018 14:55: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 801374CA80; Mon, 4 Jun 2018 14:55:08 +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 w54EaruG008125 for ; Mon, 4 Jun 2018 10:36:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id DAF8E8B327; Mon, 4 Jun 2018 14:36:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D011A8B336 for ; Mon, 4 Jun 2018 14:36:53 +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 E225CFA8C0 for ; Mon, 4 Jun 2018 14:36:40 +0000 (UTC) Received: by mail-pl0-f66.google.com with SMTP id f1-v6so19408129plt.6 for ; Mon, 04 Jun 2018 07:36:40 -0700 (PDT) Received: from centos.localdomain ([42.106.2.208]) by smtp.gmail.com with ESMTPSA id f63-v6sm23448806pfe.143.2018.06.04.07.36.37 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 07:36: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=yndiVfNe8cn0fSvMqznQAgtaJjeBrSUwZxMFygv+zR8=; b=tS0FFM8hr+ncqS7++TBmQ0z0WWGF93tB4A2120noG9je31XztzYfWedQ3UUxrmMJI2 wr4UoqNqTF/gp30oKTEyD5UkRvQRAz0la88vBPfRyOiEi5rW09njmMB+bzFeTNggt40P btMusJdRq9YFsTRcr6PYWfie8BX1kJDLeZd/awWP5Vr1KhJ3FXkrUmLPyaIFgl4YeVtB ZEJbGEQK2ZwQ37WlbRO065L3x4z3LVDds7p02Dm3xy+4bK/syn6GWch+3HrbGlC+lgOz PqNbB6TVx5oGIEkxzZKneDqWUP2zCe9sfINbPbBaycr92VK0U7C1UiqcC44rP1CczV1T VTtg== 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=yndiVfNe8cn0fSvMqznQAgtaJjeBrSUwZxMFygv+zR8=; b=ZCbM+bNU30CPeniAM2wHaqT4PzHVJWJSn8MINhQhICf4lTLJYSzVmQY+uOJrUN6zHf Qc3XdShXRiH0c6/h1uksaS3etQBY/EZ3QtnghOtpV2VPaqPrWAR4exLYL3Tzduk+avqF IrK3hawgq6QzGlo3M3vxxZnt/E8zu82OmF82RAybBdn6HnjBIa5p3tYfKLzeruPcFF/1 DpmhFyH5lLd/65Co9/b2B1C69V5gic51ACNsnKB0m7wtnR7PMKRaxzZHN3VnuXv1qSIH 47jv1dlCmUPxe06/cqBqVOKrkQ9p0N0uMkN0i3AYiaHxRFh6TgjZW9K9VgPcRfWKrnDT 0q4g== X-Gm-Message-State: ALKqPwc2OPFzHsIM7Odjv/W5L+NXX3eKQaXbaV75H/9gTnL7ib5m730q DEX2p2EcM+IhcUtKCCvglIjUe9hM X-Google-Smtp-Source: ADUXVKJ+J4lwqD2f30XP45YTfM2jP+R/dyJ3SVGRSWmZ5WmKkb9xUJAvJLas1YewFFEOVxy09CwOhg== X-Received: by 2002:a17:902:10c:: with SMTP id 12-v6mr22306664plb.252.1528122999637; Mon, 04 Jun 2018 07:36:39 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sun, 3 Jun 2018 13:42:06 +0530 Message-Id: <1528013536-22196-9-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1528013536-22196-1-git-send-email-skrtbhtngr@gmail.com> References: <1528013536-22196-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.38]); Mon, 04 Jun 2018 14:36:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 04 Jun 2018 14:36:41 +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.766 * (DATE_IN_PAST_24_48, 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.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 08/18] use VIR_AUTOFREE in src/util/vircgroup.c 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.45]); Mon, 04 Jun 2018 14:55:10 +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 code to use VIR_AUTOFREE macro wherever required. Signed-off-by: Sukrit Bhatnagar --- src/util/vircgroup.c | 526 ++++++++++++++++++-----------------------------= ---- 1 file changed, 179 insertions(+), 347 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index 0a31947..ed86d31 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -163,7 +163,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 @@ -223,7 +223,6 @@ virCgroupPartitionNeedsEscaping(const char *path) } =20 cleanup: - VIR_FREE(line); VIR_FORCE_FCLOSE(fp); return ret; } @@ -256,41 +255,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; @@ -303,7 +301,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 || @@ -313,7 +311,7 @@ virCgroupValidateMachineGroup(virCgroupPtr group, *tmp =3D '\0'; tmp =3D strrchr(group->controllers[i].placement, '/'); if (!tmp) - goto cleanup; + return false; } =20 tmp++; @@ -329,18 +327,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 @@ -378,7 +369,7 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, FILE *mounts =3D NULL; struct mntent entry; char buf[CGROUP_MAX_VAL]; - char *linksrc =3D NULL; + VIR_AUTOFREE(char *) linksrc =3D NULL; int ret =3D -1; =20 mounts =3D fopen(path, "r"); @@ -468,7 +459,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, =20 ret =3D 0; cleanup: - VIR_FREE(linksrc); VIR_FORCE_FCLOSE(mounts); return ret; } @@ -547,7 +537,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); @@ -628,9 +618,7 @@ virCgroupDetectPlacement(virCgroupPtr group, ret =3D 0; =20 cleanup: - VIR_FREE(procfile); VIR_FORCE_FCLOSE(mapping); - return ret; } =20 @@ -786,8 +774,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) @@ -800,18 +787,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 @@ -821,8 +804,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 @@ -834,18 +817,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 @@ -856,8 +835,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 @@ -875,8 +854,6 @@ virCgroupGetValueForBlkDev(virCgroupPtr group, =20 ret =3D 0; error: - VIR_FREE(str); - VIR_FREE(prefix); virStringListFree(lines); return ret; } @@ -888,17 +865,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 @@ -908,17 +880,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 @@ -928,24 +895,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 @@ -955,24 +917,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 @@ -988,7 +945,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, @@ -1001,11 +958,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; @@ -1044,11 +998,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) { @@ -1074,10 +1027,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 @@ -1085,24 +1036,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 @@ -1113,21 +1060,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 @@ -1339,9 +1279,9 @@ virCgroupNewPartition(const char *path, virCgroupPtr *group) { int ret =3D -1; - char *parentPath =3D NULL; + VIR_AUTOFREE(char *) parentPath =3D NULL; virCgroupPtr parent =3D NULL; - char *newPath =3D NULL; + VIR_AUTOFREE(char *) newPath =3D NULL; VIR_DEBUG("path=3D%s create=3D%d controllers=3D%x", path, create, controllers); =20 @@ -1381,8 +1321,6 @@ virCgroupNewPartition(const char *path, if (ret !=3D 0) virCgroupFree(group); virCgroupFree(&parent); - VIR_FREE(parentPath); - VIR_FREE(newPath); return ret; } =20 @@ -1421,18 +1359,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 @@ -1448,14 +1385,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 @@ -1477,27 +1410,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) | @@ -1505,18 +1437,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 @@ -1577,7 +1506,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); @@ -1662,7 +1591,6 @@ virCgroupNewMachineSystemd(const char *name, ret =3D 0; cleanup: virCgroupFree(&parent); - VIR_FREE(path); return ret; } =20 @@ -1894,9 +1822,10 @@ 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, *p2; size_t i; - int ret =3D -1; =20 const char *value_names[] =3D { "Read ", @@ -1919,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++) { @@ -1938,7 +1867,7 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, _("Cannot parse byte %sstat '%s'"), value_names[i], p1); - goto cleanup; + return -1; } =20 if (stats_val < 0 || @@ -1947,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; } @@ -1959,7 +1888,7 @@ virCgroupGetBlkioIoServiced(virCgroupPtr group, _("Cannot parse %srequest stat '%s'"), value_names[i], p2); - goto cleanup; + return -1; } =20 if (stats_val < 0 || @@ -1968,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 @@ -2003,9 +1927,11 @@ 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, *p2; size_t i; - int ret =3D -1; =20 const char *value_names[] =3D { "Read ", @@ -2023,28 +1949,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++) { @@ -2052,38 +1978,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 @@ -2139,24 +2059,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 @@ -2173,24 +2088,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 @@ -2207,24 +2117,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 /** @@ -2240,24 +2145,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 @@ -2275,24 +2175,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 /** @@ -2308,15 +2203,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; @@ -2324,13 +2218,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 /** @@ -2346,15 +2237,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; @@ -2362,13 +2252,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 /** @@ -2384,15 +2271,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; @@ -2400,13 +2286,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 /** @@ -2422,15 +2305,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; @@ -2438,13 +2320,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 /** @@ -2460,15 +2339,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; @@ -2476,13 +2354,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 @@ -2941,36 +2816,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; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(devstr); - VIR_FREE(majorstr); - VIR_FREE(minorstr); - return ret; + return 0; } =20 =20 @@ -3032,36 +2900,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; - - ret =3D 0; + return -1; =20 - cleanup: - VIR_FREE(devstr); - VIR_FREE(majorstr); - VIR_FREE(minorstr); - return ret; + return 0; } =20 =20 @@ -3131,10 +2992,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; @@ -3159,13 +3020,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 @@ -3202,8 +3061,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; @@ -3289,8 +3148,6 @@ virCgroupGetPercpuStats(virCgroupPtr group, =20 cleanup: virBitmapFree(cpumap); - VIR_FREE(sum_cpu_time); - VIR_FREE(buf); return ret; } =20 @@ -3461,7 +3318,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 @@ -3470,7 +3327,6 @@ virCgroupRemoveRecursively(char *grppath) break; } rc =3D virCgroupRemoveRecursively(path); - VIR_FREE(path); if (rc !=3D 0) break; } @@ -3508,10 +3364,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; @@ -3533,7 +3390,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 @@ -3549,7 +3405,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", @@ -3613,7 +3469,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; @@ -3678,7 +3533,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; @@ -3732,7 +3587,6 @@ virCgroupKillRecursiveInternal(virCgroupPtr group, =20 cleanup: virCgroupFree(&subgroup); - VIR_FREE(keypath); VIR_DIR_CLOSE(dp); return ret; } @@ -3846,9 +3700,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, @@ -3860,14 +3713,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 @@ -3877,17 +3730,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 @@ -3913,10 +3763,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; @@ -3927,18 +3776,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++) { @@ -3946,11 +3795,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); @@ -3958,8 +3807,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, NULL, MS_BIND, @@ -3967,11 +3815,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) { @@ -3984,16 +3829,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 @@ -4004,11 +3845,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)) @@ -4025,6 +3866,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 @@ -4034,8 +3877,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup, entry, uid, gid); goto cleanup; } - - VIR_FREE(entry); } if (direrr < 0) goto cleanup; @@ -4047,7 +3888,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup, goto cleanup; } =20 - VIR_FREE(base); VIR_DIR_CLOSE(dh); } =20 @@ -4055,8 +3895,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup, =20 cleanup: VIR_DIR_CLOSE(dh); - VIR_FREE(entry); - VIR_FREE(base); return ret; } =20 @@ -4071,8 +3909,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; @@ -4080,21 +3917,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; + int ret; + VIR_AUTOFREE(char *) content =3D NULL; =20 if (!cgroup) return -1; @@ -4104,7 +3937,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