Skip to content

Commit

Permalink
[kodi] fix possible resource leak (openhab#8030)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan N. Klug <[email protected]>
  • Loading branch information
J-N-K authored and andrewfg committed Aug 31, 2020
1 parent 0589cca commit 0497815
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion bundles/org.openhab.binding.kodi/pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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);
}

/***
Expand All @@ -93,6 +95,10 @@ public void close() {
session.close();
session = null;
}

if (sessionFuture != null && !sessionFuture.isDone()) {
sessionFuture.cancel(true);
}
}

public boolean isConnected() {
Expand Down

0 comments on commit 0497815

Please sign in to comment.