From 0e7c7b8b3232fa4a5ff1279f39af24ae2ab9165a Mon Sep 17 00:00:00 2001 From: Matthias Bolte <matthias.bolte@googlemail.com> Date: Sat, 30 Apr 2011 12:23:31 +0200 Subject: [PATCH] nwfilter: Fix memory leak in the ebtables subdriver Call shutdown functions for all subcomponents in nwfilterDriverShutdown. Make sure that this shutdown functions can safely be called multiple times and independent from the actual subcomponents state. --- src/conf/nwfilter_conf.c | 8 ++++++++ src/nwfilter/nwfilter_driver.c | 2 ++ src/nwfilter/nwfilter_learnipaddr.c | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 09dc32b377..615c0f1983 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -125,6 +125,7 @@ struct int_map { * only one filter update allowed */ static virMutex updateMutex; +static bool initialized = false; void virNWFilterLockFilterUpdates(void) { @@ -2971,6 +2972,8 @@ int virNWFilterConfLayerInit(virHashIterator domUpdateCB) { virNWFilterDomainFWUpdateCB = domUpdateCB; + initialized = true; + if (virMutexInitRecursive(&updateMutex)) return 1; @@ -2980,7 +2983,12 @@ int virNWFilterConfLayerInit(virHashIterator domUpdateCB) void virNWFilterConfLayerShutdown(void) { + if (!initialized) + return; + virMutexDestroy(&updateMutex); + + initialized = false; } diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index a5793062da..8af3f8ab22 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -199,6 +199,8 @@ nwfilterDriverShutdown(void) { if (!driverState) return -1; + virNWFilterConfLayerShutdown(); + virNWFilterTechDriversShutdown(); virNWFilterLearnShutdown(); nwfilterDriverLock(driverState); diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 9ee439a102..96d2a55b0e 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -873,7 +873,10 @@ virNWFilterLearnThreadsTerminate(bool allowNewThreads) { * Shutdown of this layer */ void -virNWFilterLearnShutdown(void) { +virNWFilterLearnShutdown(void) +{ + if (!pendingLearnReq) + return; virNWFilterLearnThreadsTerminate(false);