summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-08-26 12:04:52 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-08-26 12:04:52 +0300
commit3fc805bc7d0e2b017ba95c92ea02387e167bce01 (patch)
tree234a77bfb1578923122d5412a3d68beb88f08d15
parent6ddd4e4546aa64ba91779f175ce6a27724f6be57 (diff)
fixes #3649 ([Tox] Caught a rare? crash during idle)
-rw-r--r--protocols/Tox/src/tox_connection.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/protocols/Tox/src/tox_connection.cpp b/protocols/Tox/src/tox_connection.cpp
index 56c1d7a901..3b0d3c9d46 100644
--- a/protocols/Tox/src/tox_connection.cpp
+++ b/protocols/Tox/src/tox_connection.cpp
@@ -22,11 +22,15 @@ void CToxProto::OnLoggedIn()
LoadFriendList(m_tox);
}
-void CToxProto::OnLoggedFail()
+/////////////////////////////////////////////////////////////////////////////////////////
+// Tox polling callback
+
+static void sttScheduledDisconnect(void *param)
{
- SetStatus(ID_STATUS_OFFLINE);
- ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK);
- debugLogA(__FUNCTION__": failed to connect to DHT");
+ auto *ppro = (CToxProto *)param;
+ ppro->SetStatus(ID_STATUS_OFFLINE);
+ ppro->ProtoBroadcastAck(NULL, ACKTYPE_LOGIN, ACKRESULT_FAILED, nullptr, LOGINERR_NONETWORK);
+ ppro->debugLogA(__FUNCTION__": failed to connect to DHT");
}
void CToxProto::OnConnectionStatus(Tox*, Tox_Connection iNewStatus, void *pUserData)
@@ -35,10 +39,11 @@ void CToxProto::OnConnectionStatus(Tox*, Tox_Connection iNewStatus, void *pUserD
if (ppro->m_tox == nullptr)
return;
- if (iNewStatus == TOX_CONNECTION_NONE)
- ppro->OnLoggedFail();
- else
- ppro->OnLoggedIn();
+ if (iNewStatus == TOX_CONNECTION_NONE) {
+ // we cannot destroy Tox object inside its hook... #3649
+ Miranda_WaitOnHandleEx(sttScheduledDisconnect, ppro);
+ }
+ else ppro->OnLoggedIn();
}
void CToxProto::OnToxPoll()