From nobody Wed May 1 14:07:27 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1537793816671815.3127107422472; Mon, 24 Sep 2018 05:56:56 -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 895AF3082E72; Mon, 24 Sep 2018 12:56:54 +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 444625C21F; Mon, 24 Sep 2018 12:56:54 +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 EB61A4BB75; Mon, 24 Sep 2018 12:56:53 +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 w8OCuds5004581 for ; Mon, 24 Sep 2018 08:56:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 880055D9CA; Mon, 24 Sep 2018 12:56:39 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-62.phx2.redhat.com [10.3.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4731D5D9CB for ; Mon, 24 Sep 2018 12:56:39 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Sep 2018 08:56:34 -0400 Message-Id: <20180924125635.5884-2-jferlan@redhat.com> In-Reply-To: <20180924125635.5884-1-jferlan@redhat.com> References: <20180924125635.5884-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/2] lxc: Remove unnecessary error label 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.46]); Mon, 24 Sep 2018 12:56:55 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since lxcConvertSize already creates an error message, there is no need to use an error: label in lxcSetMemTune to just overwrite or essentially rewrite the same error. So remove the label. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety --- src/lxc/lxc_native.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index e1992fd1f9..cb20f1f5cf 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -763,7 +763,7 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr propertie= s) "lxc.cgroup.memory.limit_in_bytes", &value) > 0) { if (lxcConvertSize(value, &size) < 0) - goto error; + return -1; size =3D size / 1024; virDomainDefSetMemoryTotal(def, size); def->mem.hard_limit =3D virMemoryLimitTruncate(size); @@ -773,7 +773,7 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr propertie= s) "lxc.cgroup.memory.soft_limit_in_bytes", &value) > 0) { if (lxcConvertSize(value, &size) < 0) - goto error; + return -1; def->mem.soft_limit =3D virMemoryLimitTruncate(size / 1024); } =20 @@ -781,16 +781,10 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr propert= ies) "lxc.cgroup.memory.memsw.limit_in_bytes", &value) > 0) { if (lxcConvertSize(value, &size) < 0) - goto error; + return -1; def->mem.swap_hard_limit =3D virMemoryLimitTruncate(size / 1024); } return 0; - - error: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse integer: '%s'"), value); - return -1; - } =20 static int --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 14:07:27 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; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1537793807165536.8070443907446; Mon, 24 Sep 2018 05:56:47 -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 2C454300193F; Mon, 24 Sep 2018 12:56:43 +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 B66BC5C1B4; Mon, 24 Sep 2018 12:56:42 +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 1D6E7181A12E; Mon, 24 Sep 2018 12:56:42 +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 w8OCudnF004586 for ; Mon, 24 Sep 2018 08:56:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id EEAEE5D9CB; Mon, 24 Sep 2018 12:56:39 +0000 (UTC) Received: from unknown4CEB42C824F4.redhat.com (ovpn-116-62.phx2.redhat.com [10.3.116.62]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE63E5D9CA for ; Mon, 24 Sep 2018 12:56:39 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Mon, 24 Sep 2018 08:56:35 -0400 Message-Id: <20180924125635.5884-3-jferlan@redhat.com> In-Reply-To: <20180924125635.5884-1-jferlan@redhat.com> References: <20180924125635.5884-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 2/2] lxc: Resolve memory leak 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.47]); Mon, 24 Sep 2018 12:56:43 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Commit 40b5c99a modified the virConfGetValue callers to use virConfGetValueString. However, using the virConfGetValueString resulted in leaking the returned @value string in each case. So, let's modify each instance to use the VIR_AUTOFREE(char *) syntax. In some instances changing the variable name since @value was used more than once. Found by Coverity Signed-off-by: John Ferlan Reviewed-by: Erik Skultety --- src/lxc/lxc_native.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c index cb20f1f5cf..cbdec723dd 100644 --- a/src/lxc/lxc_native.c +++ b/src/lxc/lxc_native.c @@ -198,7 +198,7 @@ lxcSetRootfs(virDomainDefPtr def, virConfPtr properties) { int type =3D VIR_DOMAIN_FS_TYPE_MOUNT; - char *value =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; =20 if (virConfGetValueString(properties, "lxc.rootfs", &value) <=3D 0) return -1; @@ -679,7 +679,7 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfP= tr properties) static int lxcCreateConsoles(virDomainDefPtr def, virConfPtr properties) { - char *value =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; int nbttys =3D 0; virDomainChrDefPtr console; size_t i; @@ -756,7 +756,7 @@ lxcIdmapWalkCallback(const char *name, virConfValuePtr = value, void *data) static int lxcSetMemTune(virDomainDefPtr def, virConfPtr properties) { - char *value =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; unsigned long long size =3D 0; =20 if (virConfGetValueString(properties, @@ -767,6 +767,7 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr propertie= s) size =3D size / 1024; virDomainDefSetMemoryTotal(def, size); def->mem.hard_limit =3D virMemoryLimitTruncate(size); + VIR_FREE(value); } =20 if (virConfGetValueString(properties, @@ -775,6 +776,7 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr propertie= s) if (lxcConvertSize(value, &size) < 0) return -1; def->mem.soft_limit =3D virMemoryLimitTruncate(size / 1024); + VIR_FREE(value); } =20 if (virConfGetValueString(properties, @@ -790,23 +792,25 @@ lxcSetMemTune(virDomainDefPtr def, virConfPtr propert= ies) static int lxcSetCpuTune(virDomainDefPtr def, virConfPtr properties) { - char *value =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; =20 if (virConfGetValueString(properties, "lxc.cgroup.cpu.shares", &value) > 0) { if (virStrToLong_ull(value, NULL, 10, &def->cputune.shares) < 0) goto error; def->cputune.sharesSpecified =3D true; + VIR_FREE(value); } =20 if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_quota_us", &value) > 0) { if (virStrToLong_ll(value, NULL, 10, &def->cputune.quota) < 0) goto error; + VIR_FREE(value); } =20 if (virConfGetValueString(properties, "lxc.cgroup.cpu.cfs_period_us", - &value) > 0) { + &value) > 0) { if (virStrToLong_ull(value, NULL, 10, &def->cputune.period) < 0) goto error; } @@ -822,7 +826,7 @@ lxcSetCpuTune(virDomainDefPtr def, virConfPtr propertie= s) static int lxcSetCpusetTune(virDomainDefPtr def, virConfPtr properties) { - char *value =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; virBitmapPtr nodeset =3D NULL; =20 if (virConfGetValueString(properties, "lxc.cgroup.cpuset.cpus", @@ -830,10 +834,11 @@ lxcSetCpusetTune(virDomainDefPtr def, virConfPtr prop= erties) if (virBitmapParse(value, &def->cpumask, VIR_DOMAIN_CPUMASK_LEN) <= 0) return -1; def->placement_mode =3D VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC; + VIR_FREE(value); } =20 if (virConfGetValueString(properties, "lxc.cgroup.cpuset.mems", - &value) > 0) { + &value) > 0) { if (virBitmapParse(value, &nodeset, VIR_DOMAIN_CPUMASK_LEN) < 0) return -1; if (virDomainNumatuneSet(def->numa, @@ -943,7 +948,7 @@ lxcBlkioDeviceWalkCallback(const char *name, virConfVal= uePtr value, void *data) static int lxcSetBlkioTune(virDomainDefPtr def, virConfPtr properties) { - char *value =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; =20 if (virConfGetValueString(properties, "lxc.cgroup.blkio.weight", &value) > 0) { @@ -963,7 +968,7 @@ lxcSetBlkioTune(virDomainDefPtr def, virConfPtr propert= ies) static void lxcSetCapDrop(virDomainDefPtr def, virConfPtr properties) { - char *value =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; char **toDrop =3D NULL; const char *capString; size_t i; @@ -990,7 +995,7 @@ lxcParseConfigString(const char *config, { virDomainDefPtr vmdef =3D NULL; virConfPtr properties =3D NULL; - char *value =3D NULL; + VIR_AUTOFREE(char *) value =3D NULL; =20 if (!(properties =3D virConfReadString(config, VIR_CONF_FLAG_LXC_FORMA= T))) return NULL; @@ -1030,6 +1035,7 @@ lxcParseConfigString(const char *config, else if (arch =3D=3D VIR_ARCH_NONE && STREQ(value, "amd64")) arch =3D VIR_ARCH_X86_64; vmdef->os.arch =3D arch; + VIR_FREE(value); } =20 if (VIR_STRDUP(vmdef->os.init, "/sbin/init") < 0) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list