From nobody Mon Apr 29 19:19:28 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1499933053871360.13257511507743; Thu, 13 Jul 2017 01:04:13 -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 8B743C03070A; Thu, 13 Jul 2017 08:04:12 +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 6261A702C9; Thu, 13 Jul 2017 08:04: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 02AEE3FADF; Thu, 13 Jul 2017 08:04:12 +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 v6D84ANL031138 for ; Thu, 13 Jul 2017 04:04:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id E8B956C1F3; Thu, 13 Jul 2017 08:04:10 +0000 (UTC) Received: from caroline.brq.redhat.com (unknown [10.43.2.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7195E6C1F2 for ; Thu, 13 Jul 2017 08:04:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8B743C03070A Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8B743C03070A From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 13 Jul 2017 10:04:02 +0200 Message-Id: <281039d9a6c60823d24bf06e3f3d54702842fe1d.1499933042.git.mkletzan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] util: Don't leak linksrc in vircgroup 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.31]); Thu, 13 Jul 2017 08:04:13 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Martin Kletzander --- src/util/vircgroup.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index a53908fc9246..2912fc9be539 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -382,6 +382,8 @@ 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"); if (mounts =3D=3D NULL) { @@ -409,7 +411,6 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, } =20 if (typelen =3D=3D len && STREQLEN(typestr, tmp, len)) { - char *linksrc; struct stat sb; char *tmp2; =20 @@ -423,35 +424,35 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, VIR_FREE(controller->mountPoint); VIR_FREE(controller->linkPoint); if (VIR_STRDUP(controller->mountPoint, entry.mnt_dir) = < 0) - goto error; + goto cleanup; =20 tmp2 =3D strrchr(entry.mnt_dir, '/'); if (!tmp2) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Missing '/' separator in cgroup = mount '%s'"), entry.mnt_dir); - goto error; + goto cleanup; } =20 /* 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, ',')) { *tmp2 =3D '\0'; + VIR_FREE(linksrc); if (virAsprintf(&linksrc, "%s/%s", entry.mnt_dir, typestr) < 0) - goto error; + goto cleanup; *tmp2 =3D '/'; =20 if (lstat(linksrc, &sb) < 0) { if (errno =3D=3D ENOENT) { VIR_WARN("Controller %s co-mounted at %s i= s missing symlink at %s", typestr, entry.mnt_dir, linksrc); - VIR_FREE(linksrc); } else { virReportSystemError(errno, _("Cannot stat %s"), linksrc); - goto error; + goto cleanup; } } else { if (!S_ISLNK(sb.st_mode)) { @@ -459,6 +460,7 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, linksrc, typestr); } else { controller->linkPoint =3D linksrc; + linksrc =3D NULL; } } } @@ -468,13 +470,11 @@ virCgroupDetectMountsFromFile(virCgroupPtr group, } } =20 + ret =3D 0; + cleanup: + VIR_FREE(linksrc); VIR_FORCE_FCLOSE(mounts); - - return 0; - - error: - VIR_FORCE_FCLOSE(mounts); - return -1; + return ret; } =20 static int --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list