Should I call RtlFreeUnicodeString() after calling RtlInitUnicodeString()??

Hi.

If I call RtlInitUnicodeString() to UNICODE_STRING to assign a string, should I call RtlFreeUnicodeString()?

VOID Test()
{
    UNICODE_STRING FilePath = {0,};
    RtlInitUnicodeString(&FilePath, gszLogFilePath);

    ....

    RtlFreeUnicodeString(&FilePath);
}

MSDN(https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlinitunicodestring) does not mention RtlFreeUnicodeString().

No you should not call RtlFreeUnicodeString for any operation where you supply the buffer holding the string. This call is specifically to release the buffer created by RtlAnsiStringToUnicodeString or RtlUpcaseUnicodeString where the OS allocates the buffer.

1 Like