This is an automated email from the ASF dual-hosted git repository.

astitcher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git

commit 82cc883d1dfa709c52c41cf492d66f78d2efcd06
Author: Andrew Stitcher <astitc...@apache.org>
AuthorDate: Mon Jan 30 17:53:32 2023 -0500

    PROTON-2677: [C++ examples] Fix use after free in broker
---
 cpp/examples/broker.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/cpp/examples/broker.cpp b/cpp/examples/broker.cpp
index 6c4e24785..32591ebbb 100644
--- a/cpp/examples/broker.cpp
+++ b/cpp/examples/broker.cpp
@@ -114,6 +114,8 @@ public:
     }
     void unsubscribed() {
         DOUT(std::cerr << "Sender:   " << this << " deleting\n";);
+        sender_.user_data(nullptr);
+        sender_.close();
         delete this;
     }
 };
@@ -383,7 +385,7 @@ public:
         // Unsubscribe all senders that belong to session.
         for (proton::sender_iterator i = session.senders().begin(); i != 
session.senders().end(); ++i) {
             Sender* s = Sender::get(*i);
-            if (s->queue_) {
+            if (s && s->queue_) {
                 auto q = s->queue_;
                 s->queue_->add([=]{q->unsubscribe(s);});
             }
@@ -399,7 +401,7 @@ public:
         // Unsubscribe all senders.
         for (proton::sender_iterator i = t.connection().senders().begin(); i 
!= t.connection().senders().end(); ++i) {
             Sender* s = Sender::get(*i);
-            if (s->queue_) {
+            if (s && s->queue_) {
                 auto q = s->queue_;
                 s->queue_->add([=]{q->unsubscribe(s);});
             }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to