diff --git a/lib/icingadb/redisconnection.cpp b/lib/icingadb/redisconnection.cpp index 985aebe57..9e2b413f4 100644 --- a/lib/icingadb/redisconnection.cpp +++ b/lib/icingadb/redisconnection.cpp @@ -323,8 +323,10 @@ void RedisConnection::Connect(asio::yield_context& yc) Log(m_Parent ? LogNotice : LogInformation, "IcingaDB", "Connected to Redis server"); - if (m_ConnectedCallback) { - m_ConnectedCallback(yc); + // Operate on a copy so that the callback can set a new callback without destroying itself while running. + auto callback (m_ConnectedCallback); + if (callback) { + callback(yc); } break;