From nobody Tue May 13 11:07:58 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 15326391597681003.9762223663537; Thu, 26 Jul 2018 14:05:59 -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 B6B363002F8C; Thu, 26 Jul 2018 21:05:57 +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 4162C2010CC4; Thu, 26 Jul 2018 21:05:57 +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 D136824F13; Thu, 26 Jul 2018 21:05:56 +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 w6QL51eh024751 for ; Thu, 26 Jul 2018 17:05:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id ED82E5ED3A; Thu, 26 Jul 2018 21:05:01 +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 E115960C20 for ; Thu, 26 Jul 2018 21:04:59 +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 0238F30841AB for ; Thu, 26 Jul 2018 21:04:57 +0000 (UTC) Received: by mail-pl0-f67.google.com with SMTP id z7-v6so1336801plo.9 for ; Thu, 26 Jul 2018 14:04:56 -0700 (PDT) Received: from centos.localdomain ([42.106.3.93]) by smtp.gmail.com with ESMTPSA id z10-v6sm3279182pfh.83.2018.07.26.14.04.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:04: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=dc3fiFhFqX3xb18VsoO+J/pbT16QV4RUcStf3Rpkg3k=; b=CC2xonoG28uBcUsoqb5Auswsg4E1ivX43gZ97iv2dSwMTSrkgvOHJlb4uy0rr7SQ1Z RW3zNHPFqEL2/Lkm4mJINYIasjD3zAuihgHyuI+l4cxiIMeF0HypBeAH2AvdDBYZ1ANh i4SgHY2wIAdGSq7IWs+d/MSNsULgY42BgOEHIBh72IBAIb6QqXJD2hbApnw7yJtjd+s/ sxU2A4OVVxBbTAft8ecrnRt7mmh5Iyz21fFskXufb2lvG+94oHMmTmBM/vz4L6vZbv4/ zb9zLdhhD2kWK2nkb1slG7THYJ5vYIloIJILkbPWAwYwbV6cxcz2P6Tst22HCd9JI4U4 KAYA== 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=dc3fiFhFqX3xb18VsoO+J/pbT16QV4RUcStf3Rpkg3k=; b=n4dvIxNGDSBpyM35kR6J4mHyZO9Ci3hhBogxfSXFcQA5ultLXoj9iuI2z87E8lDHfL EzEmluII6GyHkl+kimlyqOfhBe0rTbLsOqYouM9Hp5nMaTb7SeJPJw8Kce55JE0v7+Iy QlEJrUA5VsH1XURBY8euSchPuNYlpm/Zz2vrp5s86VE8bFatB86yJ/eStKZSJvAg9bFA e8szbeeZatsDHYxk7ufdZE5IEVujUR1cK8GgDzUSdF3KLJCfTFzGnZ7AjJNqjn302aMe ebnRNMq8AdPAAj7Cpw7YBJAUwiBQKSS2bksxIIU4EnIjVi3QOVM1M5Wb59XY3az/isOQ QBvw== X-Gm-Message-State: AOUpUlGgKo0UjVaBRXGy8tp0fZoDrWdRSt23J/KzHo77/9ARdc9h9/ip MWgD/+6pjv+16MYWwo1PI4Ae9bqv X-Google-Smtp-Source: AAOMgpc9m3gIUEPe4FtzwOIejDIhtXz8ICJ7m5qQ5WfAaZ3bCf+Teb3ZpiJVFF3n1rPpkjA7nsIuKg== X-Received: by 2002:a17:902:82c7:: with SMTP id u7-v6mr3357755plz.83.1532639095861; Thu, 26 Jul 2018 14:04:55 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:10 +0530 Message-Id: <1532447562-24010-10-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532447562-24010-1-git-send-email-skrtbhtngr@gmail.com> References: <1532447562-24010-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]); Thu, 26 Jul 2018 21:04:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 26 Jul 2018 21:04:57 +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.37 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_PASS) 209.85.160.67 mail-pl0-f67.google.com 209.85.160.67 mail-pl0-f67.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.40 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 09/41] 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.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.47]); Thu, 26 Jul 2018 21:05:58 +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..6f7b5b4 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 =3D NULL; + char *p2 =3D NULL; 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 =3D NULL; + char *p2 =3D NULL; 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