Skip to content

Commit

Permalink
fix memory leak issue
Browse files Browse the repository at this point in the history
  • Loading branch information
w-gc committed Jan 13, 2025
1 parent 4c33f88 commit b54e66d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/brpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ ServerOptions::ServerOptions()
, rtmp_service(NULL)
, redis_service(NULL)
, bthread_tag(BTHREAD_TAG_DEFAULT)
, rpc_pb_message_factory(new DefaultRpcPBMessageFactory())
, rpc_pb_message_factory(NULL)
, ignore_eovercrowded(false) {
if (s_ncore > 0) {
num_threads = s_ncore + 1;
Expand Down Expand Up @@ -813,12 +813,19 @@ int Server::StartInternal(const butil::EndPoint& endpoint,
}
return -1;
}
if (opt) {
_options = *opt;
} else {
// Always reset to default options explicitly since `_options'
// may be the options for the last run or even bad options
_options = ServerOptions();

{
delete _options.rpc_pb_message_factory;
_options.rpc_pb_message_factory = NULL;

if (opt) {
_options = *opt;
} else {
// Always reset to default options explicitly since `_options'
// may be the options for the last run or even bad options
_options = ServerOptions();
_options.rpc_pb_message_factory = new DefaultRpcPBMessageFactory();
}
}

if (!_options.h2_settings.IsValid(true/*log_error*/)) {
Expand Down

0 comments on commit b54e66d

Please sign in to comment.