1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-23 02:58:00 +01:00

[disco] Fix memory leak in ServiceDiscoveryManager

The lambda we schedule in 25ms captures a strong reference to the
XMPPConnection. However the lambda is part of the scheduled action,
which we save in the renewEntityCapsScheduledAction field. This causes
a memory leak, since the ServiceDiscoveryManager now holds a strong
reference to its XMPPConnection.

Fix this by obtaining the strong reference to the XMPPConnection, if
one still exists, within the lambda.

Fixes SMACK-926.

Reported-by: Damian Minkov <damencho@jitsi.org>
This commit is contained in:
Florian Schmaus 2022-05-26 15:18:21 +02:00
parent f402a9d12d
commit 5b6dd8e3f7

View file

@ -941,9 +941,12 @@ public final class ServiceDiscoveryManager extends Manager {
} }
} }
final XMPPConnection connection = connection();
renewEntityCapsScheduledAction = scheduleBlocking(() -> { renewEntityCapsScheduledAction = scheduleBlocking(() -> {
final XMPPConnection connection = connection();
if (connection == null) {
return;
}
renewEntityCapsPerformed.incrementAndGet(); renewEntityCapsPerformed.incrementAndGet();
DiscoverInfoBuilder discoverInfoBuilder = DiscoverInfo.builder("synthetized-disco-info-response") DiscoverInfoBuilder discoverInfoBuilder = DiscoverInfo.builder("synthetized-disco-info-response")