This fixes a segfault during `LibRadosWatchNotify.WatchNotify2Timeout`.
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
if (complete) {
return;
}
+ // it might be that `this` is kept alive only because of the reference
+ // a watcher stores and which is being removed by `cancel_notify()`.
+ // to avoid use-after-free we bump up the ref counter with `guard_ptr`.
+ [[maybe_unused]] auto guard_ptr = shared_from_this();
for (auto& watcher : watchers) {
watcher->cancel_notify(ninfo.notify_id);
}
};
std::ostream &operator<<(std::ostream &out, const notify_reply_t &rhs);
-class Notify {
+class Notify : public seastar::enable_shared_from_this<Notify> {
std::set<WatchRef> watchers;
const notify_info_t ninfo;
crimson::net::ConnectionRef conn;