From 0497815f31c2dbf1b10a7cd868f63bb58a585946 Mon Sep 17 00:00:00 2001 From: J-N-K Date: Sun, 28 Jun 2020 22:33:21 +0200 Subject: [PATCH] [kodi] fix possible resource leak (#8030) Signed-off-by: Jan N. Klug --- bundles/org.openhab.binding.kodi/pom.xml | 4 +++- .../binding/kodi/internal/protocol/KodiClientSocket.java | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bundles/org.openhab.binding.kodi/pom.xml b/bundles/org.openhab.binding.kodi/pom.xml index c9e7d9fff6d85..8775aab30ea90 100644 --- a/bundles/org.openhab.binding.kodi/pom.xml +++ b/bundles/org.openhab.binding.kodi/pom.xml @@ -1,4 +1,6 @@ - + + 4.0.0 diff --git a/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/protocol/KodiClientSocket.java b/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/protocol/KodiClientSocket.java index 3b6c5dc4f04da..757e0dfa500e8 100644 --- a/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/protocol/KodiClientSocket.java +++ b/bundles/org.openhab.binding.kodi/src/main/java/org/openhab/binding/kodi/internal/protocol/KodiClientSocket.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.net.URI; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -58,6 +59,7 @@ public class KodiClientSocket { private final URI uri; private final WebSocketClient client; private Session session; + private Future sessionFuture; private final KodiClientSocketEventListener eventHandler; @@ -81,7 +83,7 @@ public synchronized void open() throws IOException { KodiWebSocketListener socket = new KodiWebSocketListener(); ClientUpgradeRequest request = new ClientUpgradeRequest(); - client.connect(socket, uri, request); + sessionFuture = client.connect(socket, uri, request); } /*** @@ -93,6 +95,10 @@ public void close() { session.close(); session = null; } + + if (sessionFuture != null && !sessionFuture.isDone()) { + sessionFuture.cancel(true); + } } public boolean isConnected() {