From nobody Thu Nov 28 10:48:04 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 1524842914620711.4237594367798; Fri, 27 Apr 2018 08:28:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17B8481DFE; Fri, 27 Apr 2018 15:28:33 +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 B353E16D36; Fri, 27 Apr 2018 15:28:32 +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 5D4A9180215F; Fri, 27 Apr 2018 15:28:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3RFPLBW032283 for ; Fri, 27 Apr 2018 11:25:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id D39C2AB3EF; Fri, 27 Apr 2018 15:25:21 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BCFB83B71; Fri, 27 Apr 2018 15:25:21 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 27 Apr 2018 16:25:05 +0100 Message-Id: <20180427152513.28928-7-berrange@redhat.com> In-Reply-To: <20180427152513.28928-1-berrange@redhat.com> References: <20180427152513.28928-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 06/14] nwfilter: fix leaking of filter parameters upon error 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: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 27 Apr 2018 15:28:33 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 The filter parameters were not correctly free'd when an error hits while adding to the hash table. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jiri Denemark --- src/nwfilter/nwfilter_gentech_driver.c | 22 ++++++---------------- src/nwfilter/nwfilter_gentech_driver.h | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 91794dd3ad..af4411d4db 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -143,19 +143,20 @@ virNWFilterRuleInstFree(virNWFilterRuleInstPtr inst) */ static int virNWFilterVarHashmapAddStdValues(virHashTablePtr table, - char *macaddr, + const char *macaddr, const virNWFilterVarValue *ipaddr) { virNWFilterVarValue *val; =20 if (macaddr) { - val =3D virNWFilterVarValueCreateSimple(macaddr); + val =3D virNWFilterVarValueCreateSimpleCopyValue(macaddr); if (!val) return -1; =20 if (virHashAddEntry(table, NWFILTER_STD_VAR_MAC, val) < 0) { + virNWFilterVarValueFree(val); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not add variable 'MAC' to hashma= p")); return -1; @@ -170,6 +171,7 @@ virNWFilterVarHashmapAddStdValues(virHashTablePtr table, if (virHashAddEntry(table, NWFILTER_STD_VAR_IP, val) < 0) { + virNWFilterVarValueFree(val); virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not add variable 'IP' to hashmap= ")); return -1; @@ -192,7 +194,7 @@ virNWFilterVarHashmapAddStdValues(virHashTablePtr table, * Returns pointer to hashmap, NULL if an error occurred. */ virHashTablePtr -virNWFilterCreateVarHashmap(char *macaddr, +virNWFilterCreateVarHashmap(const char *macaddr, const virNWFilterVarValue *ipaddr) { virHashTablePtr table =3D virNWFilterHashTableCreate(0); @@ -767,9 +769,7 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSta= tePtr driver, virNWFilterDefPtr filter; virNWFilterDefPtr newFilter; char vmmacaddr[VIR_MAC_STRING_BUFLEN] =3D {0}; - char *str_macaddr =3D NULL; virNWFilterVarValuePtr ipaddr; - char *str_ipaddr =3D NULL; =20 techdriver =3D virNWFilterTechDriverForName(drvname); =20 @@ -788,22 +788,15 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverS= tatePtr driver, return -1; =20 virMacAddrFormat(macaddr, vmmacaddr); - if (VIR_STRDUP(str_macaddr, vmmacaddr) < 0) { - rc =3D -1; - goto err_exit; - } =20 ipaddr =3D virNWFilterIPAddrMapGetIPAddr(ifname); =20 - vars1 =3D virNWFilterCreateVarHashmap(str_macaddr, ipaddr); + vars1 =3D virNWFilterCreateVarHashmap(vmmacaddr, ipaddr); if (!vars1) { rc =3D -1; goto err_exit; } =20 - str_macaddr =3D NULL; - str_ipaddr =3D NULL; - vars =3D virNWFilterCreateVarsFrom(vars1, filterparams); if (!vars) { @@ -840,9 +833,6 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSta= tePtr driver, err_exit: virNWFilterObjUnlock(obj); =20 - VIR_FREE(str_ipaddr); - VIR_FREE(str_macaddr); - return rc; } =20 diff --git a/src/nwfilter/nwfilter_gentech_driver.h b/src/nwfilter/nwfilter= _gentech_driver.h index 67092157b8..86cc677e79 100644 --- a/src/nwfilter/nwfilter_gentech_driver.h +++ b/src/nwfilter/nwfilter_gentech_driver.h @@ -57,7 +57,7 @@ int virNWFilterInstantiateFilterLate(virNWFilterDriverSta= tePtr driver, =20 int virNWFilterTeardownFilter(const virDomainNetDef *net); =20 -virHashTablePtr virNWFilterCreateVarHashmap(char *macaddr, +virHashTablePtr virNWFilterCreateVarHashmap(const char *macaddr, const virNWFilterVarValue *value); =20 int virNWFilterDomainFWUpdateCB(virDomainObjPtr vm, --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list