From 8bbb8d6a58f60d7f4f1046e540039c272193067e Mon Sep 17 00:00:00 2001 From: Tim Wiederhake Date: Fri, 8 Apr 2022 13:46:23 +0200 Subject: [PATCH] virNWFilterDriverState: Destroy mutex safely Allow nwfilterStateCleanupLocked to be called on a partially constructed driver object. This enables the next patch to simplify and fix error handling in nwfilterStateInitialize. Signed-off-by: Tim Wiederhake Reviewed-by: Michal Privoznik --- src/conf/virnwfilterobj.h | 1 + src/nwfilter/nwfilter_driver.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h index cb103280e8..b67dc017c5 100644 --- a/src/conf/virnwfilterobj.h +++ b/src/conf/virnwfilterobj.h @@ -45,6 +45,7 @@ struct _virNWFilterDriverState { /* Recursive. Hold for filter changes, instantiation or deletion */ virMutex updateLock; + bool updateLockInitialized; }; virNWFilterDef * diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index f89b5b8757..bf17c5ea66 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -173,7 +173,8 @@ nwfilterStateCleanupLocked(void) /* free inactive nwfilters */ virNWFilterObjListFree(driver->nwfilters); - virMutexDestroy(&driver->updateLock); + if (driver->updateLockInitialized) + virMutexDestroy(&driver->updateLock); g_clear_pointer(&driver, g_free); return 0; @@ -222,6 +223,7 @@ nwfilterStateInitialize(bool privileged, if (virMutexInitRecursive(&driver->updateLock) < 0) goto err_free_driverstate; + driver->updateLockInitialized = true; driver->privileged = privileged; if (!(driver->nwfilters = virNWFilterObjListNew()))