]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/osd: fix the lifetime of Notify during timeouts.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 7 Apr 2021 19:48:49 +0000 (19:48 +0000)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 8 Apr 2021 09:49:27 +0000 (09:49 +0000)
This fixes a segfault during `LibRadosWatchNotify.WatchNotify2Timeout`.

Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/crimson/osd/watch.cc
src/crimson/osd/watch.h

index 8898be8bdf3abe8028de7740d303280a0dbc59d2..ee9308e2858c25cfd24e6a38f075843d77019946 100644 (file)
@@ -210,6 +210,10 @@ void Notify::do_timeout()
   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);
   }
index c58cf3edd4a3ebcd90bb4a7ed23b36d4f5f69bb2..4b50d286050f2b5711d90af3361c3cf183ccf656 100644 (file)
@@ -106,7 +106,7 @@ struct notify_reply_t {
 };
 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;