Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kodi] fix possible resource leak #8030

Merged
merged 1 commit into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@J-N-K I 've an additional question because I've the slight feeling that we still have a potential leak in this class.

The KodiWebSocketListener sets the session = null in the onClose() method.

The onClose() method will be called by onError() too. Isn't that a potential problem too? Shouldn't we either cancel the future there too or should we omit setting session to null anyway. What's your thoughts on that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Randomly seeing this comment, did you reach a conclusion?

sessionFuture.cancel(true);
}
}

public boolean isConnected() {
Expand Down