From e0a6fbb49562f04ecabd2d8d8f302f012f3c4ddf Mon Sep 17 00:00:00 2001 From: Esme Povirk Date: Mon, 7 Oct 2024 19:27:03 +0000 Subject: [PATCH] AtSpi2: Fix stack overflow caused by LimitPolling. --- xalia/AtSpi2/AtSpiConnection.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/xalia/AtSpi2/AtSpiConnection.cs b/xalia/AtSpi2/AtSpiConnection.cs index a927bdd..c27eee9 100644 --- a/xalia/AtSpi2/AtSpiConnection.cs +++ b/xalia/AtSpi2/AtSpiConnection.cs @@ -276,7 +276,7 @@ public PollDispoable(AtSpiConnection connection, string peer) this.peer = peer; } - public void Dispose() + public void RealDispose() { var count = connection.poll_count[peer]; @@ -294,6 +294,22 @@ public void Dispose() } connection.poll_count[peer] = count - 1; } + + public void Dispose() + { + if ((connection.poll_known_sources.TryGetValue(peer, out var known_sources) && + known_sources.Count != 0) || + (connection.poll_unknown_sources.TryGetValue(peer, out var unknown_sources) && + unknown_sources.Count != 0)) + { + // this may resume a task, add some delay so we don't do this recursively + Utils.RunIdle(RealDispose); + } + else + { + connection.poll_count[peer]--; + } + } } } }