Describe the bug (描述bug)
The default ServerOptions _options of Server may leak since it will be covered by user's ServerOptions.
To Reproduce (复现方法)
ServerOptions::ServerOptions()
: ....
, rpc_pb_message_factory(new DefaultRpcPBMessageFactory()) // BAD: New here, but delete elsewhere
, ... {
// ...
}
class Server {
public:
// ...
ServerOptions _options;
// ...
~Server() {
//...
delete _options.rpc_pb_message_factory; // <--- BAD: only the last '_options' will free rpc_pb_message_factory
_options.rpc_pb_message_factory = NULL;
//...
}
};
int Server::Start(const butil::EndPoint& endpoint, const ServerOptions* opt) {
return StartInternal(
endpoint, PortRange(endpoint.port, endpoint.port), opt);
}
int Server::StartInternal(const butil::EndPoint& endpoint,
const PortRange& port_range,
const ServerOptions *opt) {
// ...
if (opt) {
_options = *opt; // <----- LEAK: _options.rpc_pb_message_factory miss free
} else {
// Always reset to default options explicitly since `_options'
// may be the options for the last run or even bad options
_options = ServerOptions(); // <----- LEAK: _options.rpc_pb_message_factory miss free
}
// ...
}
Expected behavior (期望行为)
No memory leak, pls.
Versions (各种版本)
OS:
Compiler:
brpc:
protobuf:
Additional context/screenshots (更多上下文/截图)
Describe the bug (描述bug)
The default ServerOptions
_optionsof Server may leak since it will be covered by user's ServerOptions.To Reproduce (复现方法)
Expected behavior (期望行为)
No memory leak, pls.
Versions (各种版本)
OS:
Compiler:
brpc:
protobuf:
Additional context/screenshots (更多上下文/截图)