mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
nwfilterStateInitialize: Simplify and fix error handling
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 <twiederh@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
8bbb8d6a58
commit
c11fb2132f
@ -210,18 +210,17 @@ nwfilterStateInitialize(bool privileged,
|
||||
if (root != NULL) {
|
||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||
_("Driver does not support embedded mode"));
|
||||
return -1;
|
||||
return VIR_DRV_STATE_INIT_ERROR;
|
||||
}
|
||||
|
||||
if (virGDBusHasSystemBus() &&
|
||||
!(sysbus = virGDBusGetSystemBus()))
|
||||
if (virGDBusHasSystemBus() && !(sysbus = virGDBusGetSystemBus()))
|
||||
return VIR_DRV_STATE_INIT_ERROR;
|
||||
|
||||
driver = g_new0(virNWFilterDriverState, 1);
|
||||
|
||||
driver->lockFD = -1;
|
||||
if (virMutexInitRecursive(&driver->updateLock) < 0)
|
||||
goto err_free_driverstate;
|
||||
goto error;
|
||||
|
||||
driver->updateLockInitialized = true;
|
||||
driver->privileged = privileged;
|
||||
@ -248,18 +247,19 @@ nwfilterStateInitialize(bool privileged,
|
||||
goto error;
|
||||
|
||||
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;
|
||||
|
||||
if (virNWFilterTechDriversInit(privileged) < 0)
|
||||
goto err_dhcpsnoop_shutdown;
|
||||
goto error;
|
||||
|
||||
if (virNWFilterConfLayerInit(virNWFilterTriggerRebuildImpl,
|
||||
driver) < 0)
|
||||
goto err_techdrivers_shutdown;
|
||||
if (virNWFilterConfLayerInit(virNWFilterTriggerRebuildImpl, driver) < 0)
|
||||
goto error;
|
||||
|
||||
/*
|
||||
* startup the DBus late so we don't get a reload signal while
|
||||
@ -297,22 +297,6 @@ nwfilterStateInitialize(bool privileged,
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user