Avoid potential crash on signal disconnection

(cherry picked from commit 32b7f835d8)
This commit is contained in:
Pedro J. Estébanez 2024-07-25 11:55:53 +02:00 committed by Rémi Verschelde
parent 32f2b851ab
commit 5676d398e0
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 5 additions and 1 deletions

View File

@ -2097,7 +2097,11 @@ Object::~Object() {
// Disconnect signals that connect to this object.
while (connections.size()) {
Connection c = connections.front()->get();
bool disconnected = c.signal.get_object()->_disconnect(c.signal.get_name(), c.callable, true);
Object *obj = c.callable.get_object();
bool disconnected = false;
if (likely(obj)) {
disconnected = c.signal.get_object()->_disconnect(c.signal.get_name(), c.callable, true);
}
if (unlikely(!disconnected)) {
// If the disconnect has failed, abandon the connection to avoid getting trapped in an infinite loop here.
connections.pop_front();