From f78bc1a8cb2e5149736ea050c63149ae9b30d8aa Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 16 Apr 2019 10:46:36 +0800 Subject: [PATCH] msg/Message: add SafeMessage which forbids put/get This is an opt-in wrapper around Message inheritance to prevent undesired get/put calls on the object. Instead, you must/should use a smart ptr to adjust the reference count. Signed-off-by: Patrick Donnelly Signed-off-by: Kefu Chai --- src/msg/Message.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/msg/Message.h b/src/msg/Message.h index 8ecddf588ecf..58435fce5751 100644 --- a/src/msg/Message.h +++ b/src/msg/Message.h @@ -518,6 +518,18 @@ extern void encode_message(Message *m, uint64_t features, ceph::buffer::list& bl extern Message *decode_message(CephContext *cct, int crcflags, ceph::buffer::list::const_iterator& bl); +/// this is a "safe" version of Message. it does not allow calling get/put +/// methods on its derived classes. This is intended to prevent some accidental +/// reference leaks by forcing . Instead, you must either cast the derived class to a +/// RefCountedObject to do the get/put or detach a temporary reference. +class SafeMessage : public Message { +public: + using Message::Message; +private: + using RefCountedObject::get; + using RefCountedObject::put; +}; + namespace ceph { template using ref_t = boost::intrusive_ptr; template using cref_t = boost::intrusive_ptr; -- 2.47.3