[libvirt] [PATCH] nwfilter: Fix memory leak in the ebtables subdriver

Call shutdown functions for all subcompontents in nwfilterDriverShutdown. Make sure that this shutdown functions can safely be called multiple times and independent from the actual subcompontents 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 deletions(-) diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index 09dc32b..615c0f1 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 a579306..8af3f8a 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 9ee439a..96d2a55 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); -- 1.7.0.4

On 04/30/2011 05:12 AM, Matthias Bolte wrote:
Call shutdown functions for all subcompontents in nwfilterDriverShutdown.
s/subcompontents/subcomponents/ (twice)
+++ 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;
You could omit '= false' and still get the same results, since static storage is guaranteed to be zero-initialized, but that's just style and does not have to be changed. ACK. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

2011/4/30 Eric Blake <eblake@redhat.com>:
On 04/30/2011 05:12 AM, Matthias Bolte wrote:
Call shutdown functions for all subcompontents in nwfilterDriverShutdown.
s/subcompontents/subcomponents/ (twice)
Fixed.
+++ 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;
You could omit '= false' and still get the same results, since static storage is guaranteed to be zero-initialized, but that's just style and does not have to be changed.
ACK.
I pushed it unchanged, thanks. Matthias
participants (2)
-
Eric Blake
-
Matthias Bolte