You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "w-gc (via GitHub)" <gi...@apache.org> on 2025/01/13 09:03:43 UTC

[I] [Bug] Memory leak about ServerOptions (brpc)

w-gc opened a new issue, #2871:
URL: https://github.com/apache/brpc/issues/2871

   **Describe the bug (描述bug)**
   The default ServerOptions `_options` of Server may leak since it will be covered by user's ServerOptions.
   
   **To Reproduce (复现方法)**
   ```c++
   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, pls.
   
   **Versions (各种版本)**
   OS:
   Compiler:
   brpc:
   protobuf:
   
   **Additional context/screenshots (更多上下文/截图)**
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] [Bug] Memory leak about ServerOptions (brpc)

Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright closed issue #2871: [Bug] Memory leak about ServerOptions 
URL: https://github.com/apache/brpc/issues/2871


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org


Re: [I] [Bug] Memory leak about ServerOptions (brpc)

Posted by "yanglimingcn (via GitHub)" <gi...@apache.org>.
yanglimingcn commented on issue #2871:
URL: https://github.com/apache/brpc/issues/2871#issuecomment-2586581838

   @chenBright 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org