Skip to content

_keytable_pool and _session_local_data_pool may cause memory leak. #2164

Description

@ehds

Describe the bug (描述bug)
在 Server::StartInternal 中,_keytable_pool_session_local_data_pool 通过 new 来分配内存,在 Server 析构时,会调用 Join 函数来释放其资源。 但是Join只有当 _status != RUNNING && _status != STOPPING 时才会进入析构的逻辑。

brpc/src/brpc/server.cpp

Lines 1187 to 1190 in fc885ad

int Server::Join() {
if (_status != RUNNING && _status != STOPPING) {
return -1;
}

所以如果在 Server::StartInternal 中如果状态未成为 RUNNING (由于 BuildAcceptor 失败等),那么其分配的内存无法被释放。

To Reproduce (复现方法)
开启ASAN检测,使 BuildAcceptor 失败(设置一个被占用的端口等),会检测出 memory leak 错误。

Expected behavior (期望行为)
即使 Server start 失败,应该不会内存泄漏发生。

Versions (各种版本)
OS:
Compiler:
brpc:
protobuf:

Additional context/screenshots (更多上下文/截图)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugthe code does not work as expected

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions