mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-13 16:54:27 +02:00
Use reference-counted pointer in notification callback
`this` could be deleted after `Notification::BeginExecuteNotification` exited and before `Notification::ExecuteNotificationHelper` finished. This is fixed by constructing a `Notification::Ptr` and operate on that one as it is properly reference-counted.
This commit is contained in:
parent
c6cf9c6279
commit
9060264c64
@ -398,7 +398,11 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
|
|||||||
<< "Sending " << (reminder ? "reminder " : "") << "'" << NotificationTypeToString(type) << "' notification '"
|
<< "Sending " << (reminder ? "reminder " : "") << "'" << NotificationTypeToString(type) << "' notification '"
|
||||||
<< notificationName << "' for user '" << userName << "'";
|
<< notificationName << "' for user '" << userName << "'";
|
||||||
|
|
||||||
Utility::QueueAsyncCallback(std::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text));
|
// Explicitly use Notification::Ptr to keep the reference counted while the callback is active
|
||||||
|
Notification::Ptr notification (this);
|
||||||
|
Utility::QueueAsyncCallback([notification, type, user, cr, force, author, text]() {
|
||||||
|
notification->ExecuteNotificationHelper(type, user, cr, force, author, text);
|
||||||
|
});
|
||||||
|
|
||||||
/* collect all notified users */
|
/* collect all notified users */
|
||||||
allNotifiedUsers.insert(user);
|
allNotifiedUsers.insert(user);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user