chenBright commented on code in PR #3590:
URL: https://github.com/apache/brpc/pull/3590#discussion_r4226722227
##########
src/brpc/server.cpp:
##########
@@ -1370,6 +1374,28 @@ int Server::Join() {
return 0;
}
+void Server::DestroyPreStartAllocations() {
+ if (_status == RUNNING || _status == STOPPING) {
+ // Handled by Join().
+ return;
+ }
+ if (_keytable_pool != nullptr) {
+ // Keep the TLS key valid until its pooled data has been destroyed.
+ // Deleting the key first would disable DestroyServerTLS().
+ CHECK_EQ(0, bthread_keytable_pool_destroy(_keytable_pool));
+ // Unlike Join(), no connection (thus no keytable user) can exist
+ // when the start failed before RUNNING, so the pool struct can be
+ // deleted as well.
+ delete _keytable_pool;
Review Comment:
https://github.com/apache/brpc/blob/49085f190dedc36e09546c7ef0833bf2b97aad68/src/brpc/server.cpp#L979-L984
If `bthread_init_fn` retains `_keytable_pool` after startup fails, and
`_keytable_pool` is subsequently deleted, the task will still attempt to access
it via `return_keytable()` upon exit, resulting in a use-after-free error.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]