Skip to content

Commit d1a0a20

Browse files
authored
DbgTransportSession: delete message copy when not queued (#50550)
1 parent 42f6948 commit d1a0a20

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/coreclr/debug/shared/dbgtransportsession.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,13 @@ HRESULT DbgTransportSession::SendMessage(Message *pMessage, bool fWaitsForReply)
628628
// queue).
629629
pMessage->m_sHeader.m_dwLastSeenId = m_dwLastMessageIdSeen;
630630

631+
// Check the session state.
632+
if (m_eState == SS_Closed)
633+
{
634+
// SS_Closed is bad news, we'll never recover from that so error the send immediately.
635+
return E_ABORT;
636+
}
637+
631638
// If the caller isn't waiting around for a reply we must make a copy of the message to place on the
632639
// send queue.
633640
pMessage->m_pOrigMessage = pMessage;
@@ -668,16 +675,14 @@ HRESULT DbgTransportSession::SendMessage(Message *pMessage, bool fWaitsForReply)
668675
pMessage = pMessageCopy;
669676
}
670677

671-
// Check the session state.
672-
if (m_eState == SS_Closed)
678+
// If the state is SS_Open we can send the message now.
679+
if (m_eState == SS_Open)
673680
{
674-
// SS_Closed is bad news, we'll never recover from that so error the send immediately.
675-
if (pMessageCopy)
676-
delete pMessageCopy;
677-
if (pDataBlockCopy)
678-
delete [] pDataBlockCopy;
679-
680-
return E_ABORT;
681+
// Send the message header block followed by the data block if it's provided. Any network error will
682+
// be reported internally by SendBlock and result in a transition to the SS_Resync_NC state (and an
683+
// eventual resend of the data).
684+
if (SendBlock((PBYTE)&pMessage->m_sHeader, sizeof(MessageHeader)) && pMessage->m_pbDataBlock)
685+
SendBlock(pMessage->m_pbDataBlock, pMessage->m_cbDataBlock);
681686
}
682687

683688
// Don't queue session management messages. We always recreate these if we need to re-send them.
@@ -700,15 +705,12 @@ HRESULT DbgTransportSession::SendMessage(Message *pMessage, bool fWaitsForReply)
700705
pMessage->m_pNext = NULL;
701706
}
702707
}
703-
704-
// If the state is SS_Open we can send the message now.
705-
if (m_eState == SS_Open)
708+
else
706709
{
707-
// Send the message header block followed by the data block if it's provided. Any network error will
708-
// be reported internally by SendBlock and result in a transition to the SS_Resync_NC state (and an
709-
// eventual resend of the data).
710-
if (SendBlock((PBYTE)&pMessage->m_sHeader, sizeof(MessageHeader)) && pMessage->m_pbDataBlock)
711-
SendBlock(pMessage->m_pbDataBlock, pMessage->m_cbDataBlock);
710+
if (pMessageCopy)
711+
delete pMessageCopy;
712+
if (pDataBlockCopy)
713+
delete [] pDataBlockCopy;
712714
}
713715

714716
// If the state wasn't open there's nothing more to be done. The state will eventually transition to

0 commit comments

Comments
 (0)