From: Kefu Chai Date: Tue, 16 Apr 2019 02:46:36 +0000 (+0800) Subject: msg/Message: add SafeMessage which forbids put/get X-Git-Tag: v15.1.0~2896^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F27592%2Fhead;p=ceph.git 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 --- 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;