From nobody Tue Feb 10 03:44:54 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1649423585; cv=none; d=zohomail.com; s=zohoarc; b=FJH9tfORnDxIMbGNoSap+WZswmWcFkTtWhGLXosd3DOM0d86tFQQAW9+KC8ChoGfkeEv5GJYNRQ6vEsg8OzoNJSZDHiCy8EKPduHEbFgjy5wGRrkykoHrm24gM+HaJoRhCpx1F5rF08gYq9HdcVlG6sp/XT7cBcSSjiPbON2+cw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1649423585; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=bhsnjnu4/810M0kyOufKSYag4iwP8NXI3r3gzr8u2fk=; b=TJnHn0MNry5wFnQZ/fwNYz0r04Zck/YSh9i15CJ8aPne5q6Eh/IwwAadYCLCfOPClutDns1D6Gc5/wXq4PZzxann2XY8sB8BK6eArH+E3QnQWhQS7mkgU3JaUdNW4GqUDTmPGf8Q5EsavSRWwja3NLGgMhs2JfhRkBLZabVZgXo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1649423585604737.9569811519157; Fri, 8 Apr 2022 06:13:05 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-75--M8s8WsKPFa-EZn2XQ97Xw-1; Fri, 08 Apr 2022 09:13:00 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4496E85A5A8; Fri, 8 Apr 2022 13:12:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30A201402427; Fri, 8 Apr 2022 13:12:56 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C36BC1940349; Fri, 8 Apr 2022 13:12:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2A8A41940358 for ; Fri, 8 Apr 2022 13:12:53 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EDDCE403367; Fri, 8 Apr 2022 13:12:52 +0000 (UTC) Received: from work.redhat.com (unknown [10.39.193.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E8AC416156; Fri, 8 Apr 2022 13:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1649423584; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bhsnjnu4/810M0kyOufKSYag4iwP8NXI3r3gzr8u2fk=; b=hdquwZDRx7ro0h8Bf7ARNlfyTlDU0if3P2wb3dEpFJ7DpUYrYHaPg6XhCWMuRNlebAauD5 7yvwqwCa/zKHwT4MFtN1mKXth6gdR61C7pUfj+SfWObYFtIfVX/IMkCYFnzJnMOMS+jcBk XG1tQ/MmOVKn1rgGt7BaAuCymZrMZM8= X-MC-Unique: -M8s8WsKPFa-EZn2XQ97Xw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 5/5] nwfilterStateInitialize: Simplify and fix error handling Date: Fri, 8 Apr 2022 15:12:48 +0200 Message-Id: <20220408131248.48609-6-twiederh@redhat.com> In-Reply-To: <20220408131248.48609-1-twiederh@redhat.com> References: <20220408131248.48609-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tim Wiederhake Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1649423586366100006 Content-Type: text/plain; charset="utf-8"; x-default="true" Under certain circumstances nwfilterStateInitialize could leak memory: If e.g. the call to virNWFilterConfLayerInit fails, the error path err_techdrivers_shutdown does not free the previously allocated memory held in driver->stateDir. Signed-off-by: Tim Wiederhake --- src/nwfilter/nwfilter_driver.c | 38 ++++++++++------------------------ 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index bf17c5ea66..b66ba22737 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -210,18 +210,17 @@ nwfilterStateInitialize(bool privileged, if (root !=3D NULL) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("Driver does not support embedded mode")); - return -1; + return VIR_DRV_STATE_INIT_ERROR; } =20 - if (virGDBusHasSystemBus() && - !(sysbus =3D virGDBusGetSystemBus())) + if (virGDBusHasSystemBus() && !(sysbus =3D virGDBusGetSystemBus())) return VIR_DRV_STATE_INIT_ERROR; =20 driver =3D g_new0(virNWFilterDriverState, 1); =20 driver->lockFD =3D -1; if (virMutexInitRecursive(&driver->updateLock) < 0) - goto err_free_driverstate; + goto error; =20 driver->updateLockInitialized =3D true; driver->privileged =3D privileged; @@ -248,18 +247,19 @@ nwfilterStateInitialize(bool privileged, goto error; =20 if (virNWFilterIPAddrMapInit() < 0) - goto err_free_driverstate; + goto error; + if (virNWFilterLearnInit() < 0) - goto err_exit_ipaddrmapshutdown; + goto error; + if (virNWFilterDHCPSnoopInit() < 0) - goto err_exit_learnshutdown; + goto error; =20 if (virNWFilterTechDriversInit(privileged) < 0) - goto err_dhcpsnoop_shutdown; + goto error; =20 - if (virNWFilterConfLayerInit(virNWFilterTriggerRebuildImpl, - driver) < 0) - goto err_techdrivers_shutdown; + if (virNWFilterConfLayerInit(virNWFilterTriggerRebuildImpl, driver) < = 0) + goto error; =20 /* * startup the DBus late so we don't get a reload signal while @@ -297,22 +297,6 @@ nwfilterStateInitialize(bool privileged, =20 error: nwfilterStateCleanupLocked(); - - return VIR_DRV_STATE_INIT_ERROR; - - err_techdrivers_shutdown: - virNWFilterTechDriversShutdown(); - err_dhcpsnoop_shutdown: - virNWFilterDHCPSnoopShutdown(); - err_exit_learnshutdown: - virNWFilterLearnShutdown(); - err_exit_ipaddrmapshutdown: - virNWFilterIPAddrMapShutdown(); - - err_free_driverstate: - virNWFilterObjListFree(driver->nwfilters); - g_clear_pointer(&driver, g_free); - return VIR_DRV_STATE_INIT_ERROR; } =20 --=20 2.31.1