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

wwbmmm 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 0fec5327 Fix memory leak of socket (#2169)
0fec5327 is described below

commit 0fec53275bbdb1dad16bc53a54bd039c17fd8bc3
Author: Bright Chen <[email protected]>
AuthorDate: Mon Mar 20 09:57:42 2023 +0800

    Fix memory leak of socket (#2169)
---
 src/brpc/socket.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/brpc/socket.cpp b/src/brpc/socket.cpp
index e3878c19..c603b0ec 100644
--- a/src/brpc/socket.cpp
+++ b/src/brpc/socket.cpp
@@ -1433,10 +1433,11 @@ int Socket::KeepWriteIfConnected(int fd, int err, void* 
data) {
         // Run ssl connect in a new bthread to avoid blocking
         // the current bthread (thus blocking the EventDispatcher)
         bthread_t th;
-        google::protobuf::Closure* thrd_func = brpc::NewCallback(
-            Socket::CheckConnectedAndKeepWrite, fd, err, data);
+        std::unique_ptr<google::protobuf::Closure> thrd_func(brpc::NewCallback(
+                Socket::CheckConnectedAndKeepWrite, fd, err, data));
         if ((err = bthread_start_background(&th, &BTHREAD_ATTR_NORMAL,
-                                            RunClosure, thrd_func)) == 0) {
+                                            RunClosure, thrd_func.get())) == 
0) {
+            thrd_func.release();
             return 0;
         } else {
             PLOG(ERROR) << "Fail to start bthread";


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

Reply via email to