Blob Blame History Raw
From c0b8523ca6cb824f184117f05717a6af6b9b3783 Mon Sep 17 00:00:00 2001
Message-Id: <c0b8523ca6cb824f184117f05717a6af6b9b3783@dist-git>
From: Laine Stump <laine@redhat.com>
Date: Tue, 11 May 2021 15:48:04 -0400
Subject: [PATCH] network: make it safe to call networkSetupPrivateChains()
 multiple times
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

networkSetupPrivateChains() is currently called only once per run of
libvirtd, so it can assume that errInitV4 and errInitV6 are empty/null
when it is called. In preparation for potentially calling this
function multiple times during one run, this patch moves the reset of
errInitV[46] to the top of the function, to assure no memory is
leaked.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
(cherry picked from commit de110f110fb917a31b9f33ad8e4b3c1d3284766a)

https://bugzilla.redhat.com/1958301
Signed-off-by: Laine Stump <laine@redhat.com>
Message-Id: <20210511194805.365503-2-laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/network/bridge_driver_linux.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/network/bridge_driver_linux.c b/src/network/bridge_driver_linux.c
index 9de8e93c60..b6b324d1d5 100644
--- a/src/network/bridge_driver_linux.c
+++ b/src/network/bridge_driver_linux.c
@@ -48,6 +48,10 @@ static void networkSetupPrivateChains(void)
     VIR_DEBUG("Setting up global firewall chains");
 
     createdChains = false;
+    virFreeError(errInitV4);
+    errInitV4 = NULL;
+    virFreeError(errInitV6);
+    errInitV6 = NULL;
 
     rc = iptablesSetupPrivateChains(VIR_FIREWALL_LAYER_IPV4);
     if (rc < 0) {
@@ -56,8 +60,6 @@ static void networkSetupPrivateChains(void)
         errInitV4 = virSaveLastError();
         virResetLastError();
     } else {
-        virFreeError(errInitV4);
-        errInitV4 = NULL;
         if (rc) {
             VIR_DEBUG("Created global IPv4 chains");
             createdChains = true;
@@ -73,8 +75,6 @@ static void networkSetupPrivateChains(void)
         errInitV6 = virSaveLastError();
         virResetLastError();
     } else {
-        virFreeError(errInitV6);
-        errInitV6 = NULL;
         if (rc) {
             VIR_DEBUG("Created global IPv6 chains");
             createdChains = true;
-- 
2.31.1