|
Daniel P. Berrangé |
9ae002 |
From 98f1cf88fa7e0f992d93f376418fbfb3996a9690 Mon Sep 17 00:00:00 2001
|
|
Daniel P. Berrangé |
9ae002 |
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
|
|
Daniel P. Berrangé |
9ae002 |
Date: Fri, 17 May 2024 14:55:24 +0100
|
|
Daniel P. Berrangé |
9ae002 |
Subject: [PATCH] rpc: avoid leak of GSource in use for interrupting main loop
|
|
Daniel P. Berrangé |
9ae002 |
MIME-Version: 1.0
|
|
Daniel P. Berrangé |
9ae002 |
Content-Type: text/plain; charset=UTF-8
|
|
Daniel P. Berrangé |
9ae002 |
Content-Transfer-Encoding: 8bit
|
|
Daniel P. Berrangé |
9ae002 |
|
|
Daniel P. Berrangé |
9ae002 |
We never release the reference on the GSource created for
|
|
Daniel P. Berrangé |
9ae002 |
interrupting the main loop, nor do we remove it from the
|
|
Daniel P. Berrangé |
9ae002 |
main context if our thread is woken up prior to the wakeup
|
|
Daniel P. Berrangé |
9ae002 |
callback firing.
|
|
Daniel P. Berrangé |
9ae002 |
|
|
Daniel P. Berrangé |
9ae002 |
This can result in a leak of GSource objects, along with an
|
|
Daniel P. Berrangé |
9ae002 |
ever growing list of GSources attached to the main context,
|
|
Daniel P. Berrangé |
9ae002 |
which will gradually slow down execution of the loop, as
|
|
Daniel P. Berrangé |
9ae002 |
several operations are O(N) for the number of attached GSource
|
|
Daniel P. Berrangé |
9ae002 |
objects.
|
|
Daniel P. Berrangé |
9ae002 |
|
|
Daniel P. Berrangé |
9ae002 |
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
Daniel P. Berrangé |
9ae002 |
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
Daniel P. Berrangé |
9ae002 |
---
|
|
Daniel P. Berrangé |
9ae002 |
src/rpc/virnetclient.c | 3 ++-
|
|
Daniel P. Berrangé |
9ae002 |
1 file changed, 2 insertions(+), 1 deletion(-)
|
|
Daniel P. Berrangé |
9ae002 |
|
|
Daniel P. Berrangé |
9ae002 |
diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c
|
|
Daniel P. Berrangé |
9ae002 |
index 147b0d661a..6d424eb599 100644
|
|
Daniel P. Berrangé |
9ae002 |
--- a/src/rpc/virnetclient.c
|
|
Daniel P. Berrangé |
9ae002 |
+++ b/src/rpc/virnetclient.c
|
|
Daniel P. Berrangé |
9ae002 |
@@ -1946,7 +1946,7 @@ static int virNetClientIO(virNetClient *client,
|
|
Daniel P. Berrangé |
9ae002 |
/* Check to see if another thread is dispatching */
|
|
Daniel P. Berrangé |
9ae002 |
if (client->haveTheBuck) {
|
|
Daniel P. Berrangé |
9ae002 |
/* Force other thread to wakeup from poll */
|
|
Daniel P. Berrangé |
9ae002 |
- GSource *wakeup = g_idle_source_new();
|
|
Daniel P. Berrangé |
9ae002 |
+ g_autoptr(GSource) wakeup = g_idle_source_new();
|
|
Daniel P. Berrangé |
9ae002 |
g_source_set_callback(wakeup, virNetClientIOWakeup, client->eventLoop, NULL);
|
|
Daniel P. Berrangé |
9ae002 |
g_source_attach(wakeup, client->eventCtx);
|
|
Daniel P. Berrangé |
9ae002 |
|
|
Daniel P. Berrangé |
9ae002 |
@@ -1968,6 +1968,7 @@ static int virNetClientIO(virNetClient *client,
|
|
Daniel P. Berrangé |
9ae002 |
return -1;
|
|
Daniel P. Berrangé |
9ae002 |
}
|
|
Daniel P. Berrangé |
9ae002 |
|
|
Daniel P. Berrangé |
9ae002 |
+ g_source_destroy(wakeup);
|
|
Daniel P. Berrangé |
9ae002 |
VIR_DEBUG("Woken up from sleep head=%p call=%p",
|
|
Daniel P. Berrangé |
9ae002 |
client->waitDispatch, thiscall);
|
|
Daniel P. Berrangé |
9ae002 |
/* Three reasons we can be woken up
|
|
Daniel P. Berrangé |
9ae002 |
--
|
|
Daniel P. Berrangé |
9ae002 |
2.45.1
|
|
Daniel P. Berrangé |
9ae002 |
|