This return value needs to be checked more carefully.
If the final path is longer than the buffer, then GetFinalPathNameByHandleW will return the actual length needed, which will convince this if statement that the call succeeded when it didn't, and then we'll process the uninitialized buffer.
How can the final path require a buffer longer than MAX_PATH? Two ways:
Thanks, good catch. Will update with a stack buffer that should fit all practical cases (MAX_PATH+10) and fall back on dynamic allocation if that wasn't big enough.