You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by di...@apache.org on 2020/03/17 03:07:52 UTC
[rocketmq-client-cpp] branch master updated: Fix the
heap-use-after-free risk caused by direct deconstruction when it is not
used after initialization. (#274)
This is an automated email from the ASF dual-hosted git repository.
dinglei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git
The following commit(s) were added to refs/heads/master by this push:
new 9ddb626 Fix the heap-use-after-free risk caused by direct deconstruction when it is not used after initialization. (#274)
9ddb626 is described below
commit 9ddb6263b778859b62e8d01ebe37fae5c8b89fc7
Author: yizhe.wcm <42...@users.noreply.github.com>
AuthorDate: Tue Mar 17 11:07:40 2020 +0800
Fix the heap-use-after-free risk caused by direct deconstruction when it is not used after initialization. (#274)
Fix the heap-use-after-free risk caused by direct deconstruction when it is not used after initialization. (#274)
---
src/MQClientFactory.cpp | 30 +++++++++++++++++++-----------
test/src/MQClientManagerTest.cpp | 1 +
2 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/src/MQClientFactory.cpp b/src/MQClientFactory.cpp
index d210965..6f76209 100644
--- a/src/MQClientFactory.cpp
+++ b/src/MQClientFactory.cpp
@@ -62,8 +62,6 @@ MQClientFactory::~MQClientFactory() {
m_topicRouteTable.clear();
m_brokerAddrTable.clear();
m_topicPublishInfoTable.clear();
-
- m_pClientAPIImpl = NULL;
}
void MQClientFactory::start() {
@@ -287,26 +285,36 @@ void MQClientFactory::shutdown() {
return;
switch (m_serviceState) {
+ case CREATE_JUST:
case RUNNING: {
if (m_consumer_async_service_thread) {
m_consumer_async_ioService.stop();
m_consumer_async_service_thread->interrupt();
m_consumer_async_service_thread->join();
+ m_consumer_async_service_thread.reset();
+ }
+
+ if (m_async_service_thread) {
+ m_async_ioService.stop();
+ m_async_service_thread->interrupt();
+ m_async_service_thread->join();
+ m_async_service_thread.reset();
}
- m_async_ioService.stop();
- m_async_service_thread->interrupt();
- m_async_service_thread->join();
- m_pClientAPIImpl->stopAllTcpTransportThread(); // Note: stop all
- // TcpTransport Threads
- // and release all
- // responseFuture
- // conditions
+
+ if (m_pClientAPIImpl) {
+ m_pClientAPIImpl->stopAllTcpTransportThread(); // Note: stop all
+ // TcpTransport Threads
+ // and release all
+ // responseFuture
+ // conditions
+ m_pClientAPIImpl.reset();
+ }
+
m_serviceState = SHUTDOWN_ALREADY;
LOG_INFO("MQClientFactory:%s shutdown", m_clientId.c_str());
break;
}
case SHUTDOWN_ALREADY:
- case CREATE_JUST:
break;
default:
break;
diff --git a/test/src/MQClientManagerTest.cpp b/test/src/MQClientManagerTest.cpp
index 830be46..78b336b 100644
--- a/test/src/MQClientManagerTest.cpp
+++ b/test/src/MQClientManagerTest.cpp
@@ -36,6 +36,7 @@ TEST(MQClientManagerTest, getClientFactory) {
MQClientFactory* factory = MQClientManager::getInstance()->getMQClientFactory(clientId, 1, 1000, 3000, unitName);
MQClientFactory* factory2 = MQClientManager::getInstance()->getMQClientFactory(clientId, 1, 1000, 3000, unitName);
EXPECT_EQ(factory, factory2);
+ factory->shutdown();
MQClientManager::getInstance()->removeClientFactory(clientId);
}