From 6d4897776571022c8c5609ec909d44739d399586 Mon Sep 17 00:00:00 2001 From: Bill Stoffel Date: Wed, 17 Feb 2021 15:28:11 -0600 Subject: [PATCH] Lock subscription mutex around optional trace logs - The _subscribers vector was utilized in the trace function without obtaining a lock. This vector could change size and lead to a segfault. --- cpp/src/IceStorm/TopicI.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cpp/src/IceStorm/TopicI.cpp b/cpp/src/IceStorm/TopicI.cpp index 480189c6387..122fa29b919 100644 --- a/cpp/src/IceStorm/TopicI.cpp +++ b/cpp/src/IceStorm/TopicI.cpp @@ -503,6 +503,8 @@ TopicImpl::subscribeAndGetPublisher(const QoS& qos, const Ice::ObjectPrx& obj) Ice::Identity id = obj->ice_getIdentity(); TraceLevelsPtr traceLevels = _instance->traceLevels(); + + IceUtil::Mutex::Lock sync(_subscribersMutex); if(traceLevels->topic > 0) { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); @@ -525,8 +527,6 @@ TopicImpl::subscribeAndGetPublisher(const QoS& qos, const Ice::ObjectPrx& obj) } } - IceUtil::Mutex::Lock sync(_subscribersMutex); - SubscriberRecord record; record.id = id; record.obj = obj; @@ -587,6 +587,7 @@ TopicImpl::unsubscribe(const Ice::ObjectPrx& subscriber) Ice::Identity id = subscriber->ice_getIdentity(); + IceUtil::Mutex::Lock sync(_subscribersMutex); if(traceLevels->topic > 0) { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); @@ -598,8 +599,6 @@ TopicImpl::unsubscribe(const Ice::ObjectPrx& subscriber) trace(out, _instance, _subscribers); } } - - IceUtil::Mutex::Lock sync(_subscribersMutex); Ice::IdentitySeq ids; ids.push_back(id); removeSubscribers(ids);