]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg/Message: add SafeMessage which forbids put/get 27592/head
authorKefu Chai <kchai@redhat.com>
Tue, 16 Apr 2019 02:46:36 +0000 (10:46 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 17 Apr 2019 22:59:42 +0000 (06:59 +0800)
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 <pdonnell@redhat.com>
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/msg/Message.h

index 8ecddf588ecf96cd831a6372f0a77575e17d70f7..58435fce57518cc90c16fe0e5c71a056829e8fd1 100644 (file)
@@ -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<typename T> using ref_t = boost::intrusive_ptr<T>;
 template<typename T> using cref_t = boost::intrusive_ptr<const T>;