https://git.reactos.org/?p=reactos.git;a=commitdiff;h=7cb411e88fa68419c2cce…
commit 7cb411e88fa68419c2cce8a3eb544945bd4af095
Author:     Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sat Jun 9 15:37:54 2018 +0200
Commit:     Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat Jun 9 15:37:54 2018 +0200
    [USERSRV] HardError: Free WindowTitleU buffer only if we really allocated it.
---
 win32ss/user/winsrv/usersrv/harderror.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/win32ss/user/winsrv/usersrv/harderror.c
b/win32ss/user/winsrv/usersrv/harderror.c
index 7cc3a67ca4..85ef9fe23d 100644
--- a/win32ss/user/winsrv/usersrv/harderror.c
+++ b/win32ss/user/winsrv/usersrv/harderror.c
@@ -641,8 +641,10 @@ UserpFormatMessages(
     CaptionStringU->Length = (USHORT)(wcslen(CaptionStringU->Buffer) *
sizeof(WCHAR));
     /* Free the strings if needed */
-    if (WindowTitleU.Buffer) RtlFreeUnicodeString(&WindowTitleU);
-    if (hProcess) RtlFreeUnicodeString(&FileNameU);
+    if (WindowTitleU.Buffer && (WindowTitleU.MaximumLength != 0))
+        RtlFreeUnicodeString(&WindowTitleU);
+    if (hProcess)
+        RtlFreeUnicodeString(&FileNameU);
     Format2A.Buffer = NULL;