Skip to content

Commit

Permalink
Fix memory leak of socket (#2169)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenBright authored Mar 20, 2023
1 parent 1be060d commit 0fec532
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/brpc/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 0fec532

Please sign in to comment.