Copilot commented on code in PR #3595:
URL: https://github.com/apache/brpc/pull/3595#discussion_r4237099060
##########
src/brpc/selective_channel.cpp:
##########
@@ -197,19 +201,33 @@ int ChannelBalancer::AddChannel(ChannelBase* sub_channel,
options.health_check_interval_s = FLAGS_channel_check_interval;
if (Socket::Create(options, &sock_id) != 0) {
- delete sub_chan;
+ // Socket recycles itself on failure, already running
+ // SubChannel::BeforeRecycle (deletes chan iff OWNS, then sub_chan).
+ // Do NOT delete sub_chan/chan here: that double-frees.
Review Comment:
`Socket::Create` does not always run `SubChannel::BeforeRecycle` on failure.
`Socket::OnCreated` can fail at `_io_event.Init()` before `_user =
options.user` (`socket.cpp:723-749`), and `VersionedRefWithId::Create` then
recycles a socket whose `_user` is null. This leaks `sub_chan` and, for
`OWNS_CHANNEL`, the caller's channel. The creation API or this handoff needs to
make ownership consumption observable/consistent before removing manual cleanup.
--
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]