Skip to content

Commit 33cb2e6

Browse files
fengjingchao-cnycool
authored andcommitted
fix publishing latched message many times leads to crash bug
1 parent 039a5c0 commit 33cb2e6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

ros/ros_comm/roscpp/src/libros/subscription.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -680,16 +680,19 @@ uint32_t Subscription::handleMessage(const SerializedMessage& m, bool ser, bool
680680
}
681681
}
682682

683-
for (V_PublisherLink::iterator it = publisher_links_.begin(); it != publisher_links_.end(); ++it)
684683
{
685-
if ((*it)->isLatched())
684+
boost::mutex::scoped_lock lock(publisher_links_mutex_);
685+
for (V_PublisherLink::iterator it = publisher_links_.begin(); it != publisher_links_.end(); ++it)
686686
{
687-
LatchInfo li;
688-
li.connection_header = connection_header;
689-
li.link = (*it);
690-
li.message = m;
691-
li.receipt_time = receipt_time;
692-
latched_messages_[(*it)] = li;
687+
if ((*it)->isLatched())
688+
{
689+
LatchInfo li;
690+
li.connection_header = connection_header;
691+
li.link = (*it);
692+
li.message = m;
693+
li.receipt_time = receipt_time;
694+
latched_messages_[(*it)] = li;
695+
}
693696
}
694697
}
695698

0 commit comments

Comments
 (0)