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

guangmingchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new b8d45bb9 fix LoadBalancerWithNaming memory leak when ssl init failed 
(#2503)
b8d45bb9 is described below

commit b8d45bb9c868c64e50083d677680f71e8e11489d
Author: Dongsheng He <[email protected]>
AuthorDate: Thu Jan 11 23:22:43 2024 +0800

    fix LoadBalancerWithNaming memory leak when ssl init failed (#2503)
---
 src/brpc/channel.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/brpc/channel.cpp b/src/brpc/channel.cpp
index 67ab4969..ba0e8161 100644
--- a/src/brpc/channel.cpp
+++ b/src/brpc/channel.cpp
@@ -19,6 +19,7 @@
 #include <inttypes.h>
 #include <google/protobuf/descriptor.h>
 #include <gflags/gflags.h>
+#include <memory>
 #include "butil/time.h"                              // milliseconds_from_now
 #include "butil/logging.h"
 #include "butil/third_party/murmurhash3/murmurhash3.h"
@@ -373,7 +374,8 @@ int Channel::Init(const char* ns_url,
             _options.mutable_ssl_options()->sni_name = _service_name;
         }
     }
-    LoadBalancerWithNaming* lb = new (std::nothrow) LoadBalancerWithNaming;
+    std::unique_ptr<LoadBalancerWithNaming> lb(new (std::nothrow)
+                                                   LoadBalancerWithNaming);
     if (NULL == lb) {
         LOG(FATAL) << "Fail to new LoadBalancerWithNaming";
         return -1;        
@@ -388,10 +390,9 @@ int Channel::Init(const char* ns_url,
     }
     if (lb->Init(ns_url, lb_name, _options.ns_filter, &ns_opt) != 0) {
         LOG(ERROR) << "Fail to initialize LoadBalancerWithNaming";
-        delete lb;
         return -1;
     }
-    _lb.reset(lb);
+    _lb.reset(lb.release());
     return 0;
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to