Skip to content

Commit 0d53774

Browse files
ymmyysclaude
authored andcommitted
net/barex: erase channelComm entry and free comm on HELLO error paths
Once comm is inserted into e->channelComm[ch], the three HELLO error paths (AllocBuffer failure, Send sync error, helloFailed) returned after only deleting st. This leaked the BarexComm and left a dangling channelComm[ch] -> comm entry that a later OnRecvCall (e.g. a CTS on this channel) would look up and dereference. Erase the map entry under e->mu and delete comm before returning on each path. Reported by Copilot review on PR #526. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 94a424f commit 0d53774

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

flagcx/adaptor/net/barex_adaptor.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ static flagcxResult_t barexConnect(int dev, void *opaqueHandle,
601601
ch->GetLocalNicId(),
602602
0) != accl::barex::BAREX_SUCCESS) {
603603
WARN("NET/BAREX : HELLO buffer alloc failed");
604+
{
605+
std::lock_guard<std::mutex> lk(e->mu);
606+
e->channelComm.erase(ch);
607+
}
608+
delete comm;
604609
delete st;
605610
handle->connectState = nullptr;
606611
return flagcxInternalError;
@@ -626,6 +631,11 @@ static flagcxResult_t barexConnect(int dev, void *opaqueHandle,
626631
WARN("NET/BAREX : HELLO send sync error: %s", bxstr(r));
627632
/* per xchannel.h: on send failure the buffer is NOT auto-released */
628633
e->mempool->ReleaseBuffer(msg.buf, accl::barex::CPU);
634+
{
635+
std::lock_guard<std::mutex> lk(e->mu);
636+
e->channelComm.erase(ch);
637+
}
638+
delete comm;
629639
delete st;
630640
handle->connectState = nullptr;
631641
return flagcxInternalError;
@@ -636,6 +646,11 @@ static flagcxResult_t barexConnect(int dev, void *opaqueHandle,
636646

637647
if (st->helloFailed.load(std::memory_order_acquire)) {
638648
WARN("NET/BAREX : HELLO delivery failed");
649+
if (st->comm != nullptr) {
650+
std::lock_guard<std::mutex> lk(e->mu);
651+
e->channelComm.erase(st->comm->channel);
652+
}
653+
delete st->comm;
639654
delete st;
640655
handle->connectState = nullptr;
641656
return flagcxInternalError;

0 commit comments

Comments
 (0)