diff --git a/src/brpc/server.cpp b/src/brpc/server.cpp index ade8e274d5..c62c36b1a2 100644 --- a/src/brpc/server.cpp +++ b/src/brpc/server.cpp @@ -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; @@ -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*/)) {