From 2988d18a77dcdc58f6e7f1c16ffe5f62900bb15b Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 14 十二月 2022 17:20:26 +0800
Subject: [PATCH] fixed memory leak

---
 src/interface_bus_api.cpp |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/interface_bus_api.cpp b/src/interface_bus_api.cpp
index ccb75c8..9d110c7 100644
--- a/src/interface_bus_api.cpp
+++ b/src/interface_bus_api.cpp
@@ -31,6 +31,7 @@
         bus *b = new bus;
         bhome_msg::ProcInfo pi;
         if (pi.ParseFromArray(proc_info, proc_info_len)) get<8>(*b) = pi.proc_id();
+        std::move(pi);
 
         const auto& url_hb = get_url(URLHeartBeat);
         respond_survey(url_hb,string{(char*)proc_info,(size_t)proc_info_len},&get<5>(*b));
@@ -106,8 +107,11 @@
     for(int i = 0; i < mtl.topic_list_size(); i++){
         mtl2.add_topic_list(mtl.topic_list(i));
     }
+    std::move(mtl);
 
     string msg(mtl2.SerializeAsString());
+    std::move(mtl2);
+
     const auto& url = get_url(URLRegTopic);
     if (url.empty()) {
         set_last_error("bus_register_topics url empty");
@@ -135,7 +139,7 @@
         return false;
     }
 
-    auto url(get_url(URLQueryTopic));
+    const auto& url = get_url(URLQueryTopic);
     if (url.empty()) {
         set_last_error("bus_query_topic_address url empty");
         return false;
@@ -173,7 +177,7 @@
         return false;
     }
 
-    auto url(get_url(URLQueryProcs));
+    const auto& url = get_url(URLQueryProcs);
     if (url.empty()) {
         set_last_error("bus_query_procs url empty");
         return false;
@@ -221,6 +225,7 @@
     for(int i = 0; i < mtl.topic_list_size(); i ++){
         subscribe_topic(mtl.topic_list(i), &get<2>(*b));
     }
+    std::move(mtl);
 
 ///////////////////////////////////////////////////
     auto ret = simple_request(url, topics, topics_len, reply, reply_len, timeout_ms);
@@ -283,6 +288,8 @@
     newPub.set_data(string{(const char*)msgpub, (const size_t)msgpub_len});
 
     string msg(newPub.SerializeAsString());
+    std::move(newPub);
+
     auto ret = publish(pub.topic(), msg.data(), msg.size(), &get<1>(*b));
     if (ret > 0) return true;
     return false;

--
Gitblit v1.8.0