You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tubemq.apache.org by go...@apache.org on 2020/10/09 10:29:26 UTC

[incubator-tubemq] branch master updated: [TUBEMQ-371]Found a small amount of memory leaks in the C/C++ SDK (#283)

This is an automated email from the ASF dual-hosted git repository.

gosonzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tubemq.git


The following commit(s) were added to refs/heads/master by this push:
     new d4e02b9  [TUBEMQ-371]Found a small amount of memory leaks in the C/C++ SDK (#283)
d4e02b9 is described below

commit d4e02b9190a41c0d0d85613a1c7ddb576a6c8b14
Author: charlely <41...@users.noreply.github.com>
AuthorDate: Fri Oct 9 18:28:46 2020 +0800

    [TUBEMQ-371]Found a small amount of memory leaks in the C/C++ SDK (#283)
    
    Co-authored-by: charleli <ch...@tencent.com>
---
 tubemq-client-twins/tubemq-client-cpp/src/client_service.cc | 4 ++--
 tubemq-client-twins/tubemq-client-cpp/src/connection_pool.h | 6 ++++--
 tubemq-client-twins/tubemq-client-cpp/src/logger.cc         | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/tubemq-client-twins/tubemq-client-cpp/src/client_service.cc b/tubemq-client-twins/tubemq-client-cpp/src/client_service.cc
index cbaabf4..2a4d8f5 100644
--- a/tubemq-client-twins/tubemq-client-cpp/src/client_service.cc
+++ b/tubemq-client-twins/tubemq-client-cpp/src/client_service.cc
@@ -105,10 +105,10 @@ bool TubeMQService::Stop(string& err_info) {
       dns_xfs_thread_.join();
     }
     shutDownClinets();
-    timer_executor_->Close();
-    network_executor_->Close();
     connection_pool_ = nullptr;
     thread_pool_ = nullptr;
+    timer_executor_->Close();
+    network_executor_->Close();
     LOG_INFO("[TubeMQService] TubeMQ service stopped!");
   }
   err_info = "OK!";
diff --git a/tubemq-client-twins/tubemq-client-cpp/src/connection_pool.h b/tubemq-client-twins/tubemq-client-cpp/src/connection_pool.h
index 8ca1881..16db1c8 100644
--- a/tubemq-client-twins/tubemq-client-cpp/src/connection_pool.h
+++ b/tubemq-client-twins/tubemq-client-cpp/src/connection_pool.h
@@ -43,7 +43,7 @@ namespace tubemq {
 
 using std::string;
 
-class ConnectionPool : noncopyable {
+class ConnectionPool : public noncopyable, public std::enable_shared_from_this<ConnectionPool> {
  public:
   explicit ConnectionPool(ExecutorPoolPtr& executor_pool)
       : executor_pool_(executor_pool), regular_timer_(executor_pool_->Get()->CreateSteadyTimer()) {
@@ -80,7 +80,9 @@ class ConnectionPool : noncopyable {
       ++it;
     }
     regular_timer_->expires_after(std::chrono::seconds(kRegularTimerSecond));
-    regular_timer_->async_wait([this](const std::error_code& ec) { ClearInvalidConnect(ec); });
+    auto self = shared_from_this();
+    regular_timer_->async_wait(
+        [this, self](const std::error_code& ec) { ClearInvalidConnect(ec); });
   }
 
   ConnectionPtr GetConnection(RequestContextPtr& request) {
diff --git a/tubemq-client-twins/tubemq-client-cpp/src/logger.cc b/tubemq-client-twins/tubemq-client-cpp/src/logger.cc
index eb03ad3..81c010b 100644
--- a/tubemq-client-twins/tubemq-client-cpp/src/logger.cc
+++ b/tubemq-client-twins/tubemq-client-cpp/src/logger.cc
@@ -57,8 +57,8 @@ bool Logger::Write(const char* format, ...) {
 
 bool Logger::writeStream(const char* log) {
   auto logger = log4cplus::Logger::getInstance(instance_);
-  // log4cplus::tostringstream _log4cplus_buf;
-  //_log4cplus_buf << log;
+  // log4cplus::tostringstream log4cplus_buf;
+  // log4cplus_buf << log;
   logger.forcedLog(log4cplus::TRACE_LOG_LEVEL, log);
   return true;
 }