Fix WebSocketClient crash when unref during signal
Always call disconnect before emitting signals, to avoid calling it on a freed object if the user decides to unreference it in a signal.
This commit is contained in:
parent
331a703f5d
commit
d6c9b377b9
@ -190,8 +190,8 @@ Error WSLClient::connect_to_host(String p_host, String p_path, uint16_t p_port,
|
|||||||
|
|
||||||
Error err = _tcp->connect_to_host(addr, p_port);
|
Error err = _tcp->connect_to_host(addr, p_port);
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
_on_error();
|
|
||||||
_tcp->disconnect_from_host();
|
_tcp->disconnect_from_host();
|
||||||
|
_on_error();
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
_connection = _tcp;
|
_connection = _tcp;
|
||||||
@ -230,8 +230,8 @@ void WSLClient::poll() {
|
|||||||
if (_peer->is_connected_to_host()) {
|
if (_peer->is_connected_to_host()) {
|
||||||
_peer->poll();
|
_peer->poll();
|
||||||
if (!_peer->is_connected_to_host()) {
|
if (!_peer->is_connected_to_host()) {
|
||||||
_on_disconnect(_peer->close_code != -1);
|
|
||||||
disconnect_from_host();
|
disconnect_from_host();
|
||||||
|
_on_disconnect(_peer->close_code != -1);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -242,8 +242,8 @@ void WSLClient::poll() {
|
|||||||
switch (_tcp->get_status()) {
|
switch (_tcp->get_status()) {
|
||||||
case StreamPeerTCP::STATUS_NONE:
|
case StreamPeerTCP::STATUS_NONE:
|
||||||
// Clean close
|
// Clean close
|
||||||
_on_error();
|
|
||||||
disconnect_from_host();
|
disconnect_from_host();
|
||||||
|
_on_error();
|
||||||
break;
|
break;
|
||||||
case StreamPeerTCP::STATUS_CONNECTED: {
|
case StreamPeerTCP::STATUS_CONNECTED: {
|
||||||
Ref<StreamPeerSSL> ssl;
|
Ref<StreamPeerSSL> ssl;
|
||||||
@ -255,8 +255,8 @@ void WSLClient::poll() {
|
|||||||
ERR_FAIL_COND(ssl.is_null());
|
ERR_FAIL_COND(ssl.is_null());
|
||||||
ssl->set_blocking_handshake_enabled(false);
|
ssl->set_blocking_handshake_enabled(false);
|
||||||
if (ssl->connect_to_stream(_tcp, verify_ssl, _host) != OK) {
|
if (ssl->connect_to_stream(_tcp, verify_ssl, _host) != OK) {
|
||||||
_on_error();
|
|
||||||
disconnect_from_host();
|
disconnect_from_host();
|
||||||
|
_on_error();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_connection = ssl;
|
_connection = ssl;
|
||||||
@ -268,8 +268,8 @@ void WSLClient::poll() {
|
|||||||
if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING)
|
if (ssl->get_status() == StreamPeerSSL::STATUS_HANDSHAKING)
|
||||||
return; // Need more polling.
|
return; // Need more polling.
|
||||||
else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
|
else if (ssl->get_status() != StreamPeerSSL::STATUS_CONNECTED) {
|
||||||
_on_error();
|
|
||||||
disconnect_from_host();
|
disconnect_from_host();
|
||||||
|
_on_error();
|
||||||
return; // Error.
|
return; // Error.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -277,8 +277,8 @@ void WSLClient::poll() {
|
|||||||
_do_handshake();
|
_do_handshake();
|
||||||
} break;
|
} break;
|
||||||
case StreamPeerTCP::STATUS_ERROR:
|
case StreamPeerTCP::STATUS_ERROR:
|
||||||
_on_error();
|
|
||||||
disconnect_from_host();
|
disconnect_from_host();
|
||||||
|
_on_error();
|
||||||
break;
|
break;
|
||||||
case StreamPeerTCP::STATUS_CONNECTING:
|
case StreamPeerTCP::STATUS_CONNECTING:
|
||||||
break; // Wait for connection
|
break; // Wait for connection
|
||||||
|
Loading…
Reference in New Issue
Block a user