Skip to content

Commit 36cc209

Browse files
committed
Avoid mSocket NPE if WebSocketClient.disconnect() is called twice
1 parent 7555935 commit 36cc209

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/com/codebutler/android_websockets/WebSocketClient.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,16 @@ public void disconnect() {
150150
mHandler.post(new Runnable() {
151151
@Override
152152
public void run() {
153-
try {
154-
mSocket.close();
153+
if (mSocket != null) {
154+
try {
155+
mSocket.close();
156+
} catch (IOException ex) {
157+
Log.d(TAG, "Error while disconnecting", ex);
158+
mListener.onError(ex);
159+
}
155160
mSocket = null;
156-
mConnected = false;
157-
} catch (IOException ex) {
158-
Log.d(TAG, "Error while disconnecting", ex);
159-
mListener.onError(ex);
160161
}
162+
mConnected = false;
161163
}
162164
});
163165
}

0 commit comments

Comments
 (0)