[libvirt] [PATCH 2/2] nwfilter: fix error handling

Ján Tomko jtomko at redhat.com
Fri Nov 30 12:09:22 UTC 2012


Commit 4efde75f introduced a return in the cleanup path and removed
virNWFilterConfLayerShutdown.

Found by coverity:
Error: UNREACHABLE (CWE-561):
    libvirt-0.10.2/src/nwfilter/nwfilter_driver.c:259: unreachable: This
    code cannot be reached: "nwfilterDriverUnlock(driver...".
---
I wonder if the if (!privileged) check should be moved before driverState
allocation?
---
 src/nwfilter/nwfilter_driver.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index a0ee4f1..cd185e2 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -174,8 +174,10 @@ nwfilterDriverStartup(bool privileged)
     sysbus = virDBusGetSystemBus();
 #endif /* HAVE_DBUS */
 
-    if (VIR_ALLOC(driverState) < 0)
-        goto alloc_err_exit;
+    if (VIR_ALLOC(driverState) < 0) {
+        virReportOOMError();
+        return -1;
+    }
 
     if (virMutexInit(&driverState->lock) < 0)
         goto err_free_driverstate;
@@ -247,10 +249,7 @@ error:
     nwfilterDriverUnlock(driverState);
     nwfilterDriverShutdown();
 
-alloc_err_exit:
-    return -1;
-
-    nwfilterDriverUnlock(driverState);
+    virNWFilterConfLayerShutdown();
 
 err_techdrivers_shutdown:
     virNWFilterTechDriversShutdown();
-- 
1.7.8.6




More information about the libvir-list mailing list