mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 22:05:47 +00: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) {
|
if (root != NULL) {
|
||||||
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
||||||
_("Driver does not support embedded mode"));
|
_("Driver does not support embedded mode"));
|
||||||
return -1;
|
return VIR_DRV_STATE_INIT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virGDBusHasSystemBus() &&
|
if (virGDBusHasSystemBus() && !(sysbus = virGDBusGetSystemBus()))
|
||||||
!(sysbus = virGDBusGetSystemBus()))
|
|
||||||
return VIR_DRV_STATE_INIT_ERROR;
|
return VIR_DRV_STATE_INIT_ERROR;
|
||||||
|
|
||||||
driver = g_new0(virNWFilterDriverState, 1);
|
driver = g_new0(virNWFilterDriverState, 1);
|
||||||
|
|
||||||
driver->lockFD = -1;
|
driver->lockFD = -1;
|
||||||
if (virMutexInitRecursive(&driver->updateLock) < 0)
|
if (virMutexInitRecursive(&driver->updateLock) < 0)
|
||||||
goto err_free_driverstate;
|
goto error;
|
||||||
|
|
||||||
driver->updateLockInitialized = true;
|
driver->updateLockInitialized = true;
|
||||||
driver->privileged = privileged;
|
driver->privileged = privileged;
|
||||||
@ -248,18 +247,19 @@ nwfilterStateInitialize(bool privileged,
|
|||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virNWFilterIPAddrMapInit() < 0)
|
if (virNWFilterIPAddrMapInit() < 0)
|
||||||
goto err_free_driverstate;
|
goto error;
|
||||||
|
|
||||||
if (virNWFilterLearnInit() < 0)
|
if (virNWFilterLearnInit() < 0)
|
||||||
goto err_exit_ipaddrmapshutdown;
|
goto error;
|
||||||
|
|
||||||
if (virNWFilterDHCPSnoopInit() < 0)
|
if (virNWFilterDHCPSnoopInit() < 0)
|
||||||
goto err_exit_learnshutdown;
|
goto error;
|
||||||
|
|
||||||
if (virNWFilterTechDriversInit(privileged) < 0)
|
if (virNWFilterTechDriversInit(privileged) < 0)
|
||||||
goto err_dhcpsnoop_shutdown;
|
goto error;
|
||||||
|
|
||||||
if (virNWFilterConfLayerInit(virNWFilterTriggerRebuildImpl,
|
if (virNWFilterConfLayerInit(virNWFilterTriggerRebuildImpl, driver) < 0)
|
||||||
driver) < 0)
|
goto error;
|
||||||
goto err_techdrivers_shutdown;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* startup the DBus late so we don't get a reload signal while
|
* startup the DBus late so we don't get a reload signal while
|
||||||
@ -297,22 +297,6 @@ nwfilterStateInitialize(bool privileged,
|
|||||||
|
|
||||||
error:
|
error:
|
||||||
nwfilterStateCleanupLocked();
|
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;
|
return VIR_DRV_STATE_INIT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user