PROTON-1959: [cpp] Zero pn_listener_t* in  proton::listener::stop()

Pointer becomes invalid sometime after stop() so must not be used again.


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/77ddf4b0
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/77ddf4b0
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/77ddf4b0

Branch: refs/heads/master
Commit: 77ddf4b03afb89a21e29698fcd90117e4d63b314
Parents: 84b0129
Author: Alan Conway <[email protected]>
Authored: Tue Oct 30 15:01:07 2018 -0400
Committer: Alan Conway <[email protected]>
Committed: Tue Oct 30 16:37:01 2018 -0400

----------------------------------------------------------------------
 cpp/src/listener.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/77ddf4b0/cpp/src/listener.cpp
----------------------------------------------------------------------
diff --git a/cpp/src/listener.cpp b/cpp/src/listener.cpp
index b62d171..910be1f 100644
--- a/cpp/src/listener.cpp
+++ b/cpp/src/listener.cpp
@@ -37,9 +37,15 @@ listener::listener(const listener& l) : 
listener_(l.listener_) {}
 listener::~listener() {}
 listener& listener::operator=(const listener& l) { listener_ = l.listener_; 
return *this; }
 
-void listener::stop() { if (listener_) pn_listener_close(listener_); }
+void listener::stop() {
+    if (listener_) {
+        pn_listener_close(listener_);
+        listener_ = 0;          // Further calls to stop() are no-op
+    }
+}
 
 int listener::port() {
+    if (!listener_) throw error("listener is closed");
     char port[16] = "";
     pn_netaddr_host_port(pn_listener_addr(listener_), NULL, 0, port, 
sizeof(port));
     int i = atoi(port);
@@ -48,8 +54,9 @@ int listener::port() {
 }
 
 class container& listener::container() const {
+    if (!listener_) throw error("listener is closed");
     void *c = pn_listener_get_context(listener_);
-    if (!c) throw proton::error("No container");
+    if (!c) throw proton::error("no container");
     return *reinterpret_cast<class container*>(c);
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to