ConIoSrvComm::Connect memory leak #9392

Open
opened 2026-01-31 01:53:21 +00:00 by claunia · 0 comments
Owner

Originally created by @dmex on GitHub (Jul 2, 2020).

The ConIoSrvComm::Connect function has a memory leak from using the RtlCreateUnicodeString function incorrectly:

396cbbb151/src/interactivity/onecore/ConIoSrvComm.cpp (L101-L106)

RtlCreateUnicodeString creates a copy of the string on the process heap and the PortName variable has local-scope. The string doesn't get freed with RtlFreeUnicodeString before the function returns creating a memory leak.

CIS_ALPC_PORT_NAME is a constant string and the PortName variable should instead be initialized using the RTL_CONSTANT_STRING macro:

static UNICODE_STRING PortName = RTL_CONSTANT_STRING(CIS_ALPC_PORT_NAME);

It could alternatively use RtlInitUnicodeString but since the string is hard-coded it should be using the macro.

Originally created by @dmex on GitHub (Jul 2, 2020). The ConIoSrvComm::Connect function has a memory leak from using the RtlCreateUnicodeString function incorrectly: https://github.com/microsoft/terminal/blob/396cbbb151ccd6fc9ae0356771ce1a5af5623e48/src/interactivity/onecore/ConIoSrvComm.cpp#L101-L106 RtlCreateUnicodeString creates a copy of the string on the process heap and the PortName variable has local-scope. The string doesn't get freed with RtlFreeUnicodeString before the function returns creating a memory leak. CIS_ALPC_PORT_NAME is a constant string and the PortName variable should instead be initialized using the RTL_CONSTANT_STRING macro: `static UNICODE_STRING PortName = RTL_CONSTANT_STRING(CIS_ALPC_PORT_NAME);` It could alternatively use RtlInitUnicodeString but since the string is hard-coded it should be using the macro.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#9392