Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MM-46402: Use pointer to pointer to set pointer to nil #20827

Merged
merged 5 commits into from
Aug 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2060,12 +2060,12 @@ func withMut(mut *sync.Mutex, f func()) {
f()
}

func cancelTask(mut *sync.Mutex, task *model.ScheduledTask) {
func cancelTask(mut *sync.Mutex, task **model.ScheduledTask) {
ashishbhate marked this conversation as resolved.
Show resolved Hide resolved
mut.Lock()
defer mut.Unlock()
if task != nil {
task.Cancel()
task = nil
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here just the local variable (task) containing the pointer was being set to nil.
We needed to set the pointer of the global task variable (a.ch.dndTask or a.ch.postReminderTask, depending on where this function was called) to nil.

if *task != nil {
(**task).Cancel()
*task = nil
}
}

Expand All @@ -2082,7 +2082,7 @@ func runDNDStatusExpireJob(a *App) {
a.ch.dndTask = model.CreateRecurringTaskFromNextIntervalTime("Unset DND Statuses", a.UpdateDNDStatusOfUsers, 5*time.Minute)
})
} else {
cancelTask(&a.ch.dndTaskMut, a.ch.dndTask)
cancelTask(&a.ch.dndTaskMut, &a.ch.dndTask)
}
})
}
Expand All @@ -2100,7 +2100,7 @@ func runPostReminderJob(a *App) {
a.ch.postReminderTask = model.CreateRecurringTaskFromNextIntervalTime("Check Post reminders", a.CheckPostReminders, 5*time.Minute)
})
} else {
cancelTask(&a.ch.postReminderMut, a.ch.postReminderTask)
cancelTask(&a.ch.postReminderMut, &a.ch.postReminderTask)
}
})
}
Expand Down