diff options
Diffstat (limited to 'cpp/broker/src/Channel.cpp')
-rw-r--r-- | cpp/broker/src/Channel.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/cpp/broker/src/Channel.cpp b/cpp/broker/src/Channel.cpp index 6980fe5a1b..f1f7d63a39 100644 --- a/cpp/broker/src/Channel.cpp +++ b/cpp/broker/src/Channel.cpp @@ -57,11 +57,14 @@ void Channel::consume(string& tag, Queue::shared_ptr queue, bool acks, bool excl } void Channel::cancel(string& tag){ - ConsumerImpl* c = consumers[tag]; - if(c){ - c->cancel(); - consumers.erase(tag); - delete c; + consumer_iterator i = consumers.find(tag); + if(i != consumers.end()){ + ConsumerImpl* c = i->second; + consumers.erase(i); + if(c){ + c->cancel(); + delete c; + } } } @@ -69,9 +72,11 @@ void Channel::close(){ //cancel all consumers for(consumer_iterator i = consumers.begin(); i != consumers.end(); i = consumers.begin() ){ ConsumerImpl* c = i->second; - c->cancel(); consumers.erase(i); - delete c; + if(c){ + c->cancel(); + delete c; + } } } |