]> xenbits.xensource.com Git - libvirt.git/commitdiff
network: make it safe to call networkSetupPrivateChains() multiple times
authorLaine Stump <laine@redhat.com>
Fri, 8 May 2020 02:32:59 +0000 (22:32 -0400)
committerLaine Stump <laine@redhat.com>
Tue, 12 May 2020 02:53:36 +0000 (22:53 -0400)
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>
src/network/bridge_driver_linux.c

index 7bbde5c6a9e9c3bcf1eb3e9c74dbd81e28c8ca37..80bd2409e1249206531fd0de9987e28caa3a958f 100644 (file)
@@ -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;