Skip to content

Commit d6f6839

Browse files
authored
[WINLOGON] Fix memory and handle leaks (reactos#8514)
JIRA issue: CORE-13213
1 parent abc2acf commit d6f6839

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

base/system/winlogon/winlogon.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ UpdateTcpIpInformation(VOID)
217217
else
218218
{
219219
ERR("WL: Could not reallocate memory for pszBuffer\n");
220+
goto Quit;
220221
}
221222
}
222223
if ((lError == ERROR_SUCCESS) && (dwType == REG_SZ))
@@ -278,6 +279,7 @@ UpdateTcpIpInformation(VOID)
278279
else
279280
{
280281
ERR("WL: Could not reallocate memory for pszBuffer\n");
282+
goto Quit;
281283
}
282284
}
283285
if ((lError == ERROR_SUCCESS) && (dwType == REG_SZ))
@@ -297,6 +299,7 @@ UpdateTcpIpInformation(VOID)
297299
if (pszBuffer != szBuffer)
298300
HeapFree(GetProcessHeap(), 0, pszBuffer);
299301

302+
Quit:
300303
RegCloseKey(hKey);
301304
}
302305

base/system/winlogon/wlx.c

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -957,10 +957,10 @@ CreateWindowStationAndDesktops(
957957
SECURITY_ATTRIBUTES ApplicationDesktopSecurity;
958958
SECURITY_ATTRIBUTES WinlogonDesktopSecurity;
959959
SECURITY_ATTRIBUTES ScreenSaverDesktopSecurity;
960-
PSECURITY_DESCRIPTOR WlWinstaSecurityDescriptor;
961-
PSECURITY_DESCRIPTOR WlApplicationDesktopSecurityDescriptor;
962-
PSECURITY_DESCRIPTOR WlWinlogonDesktopSecurityDescriptor;
963-
PSECURITY_DESCRIPTOR WlScreenSaverDesktopSecurityDescriptor;
960+
PSECURITY_DESCRIPTOR WlWinstaSecurityDescriptor = NULL;
961+
PSECURITY_DESCRIPTOR WlApplicationDesktopSecurityDescriptor = NULL;
962+
PSECURITY_DESCRIPTOR WlWinlogonDesktopSecurityDescriptor = NULL;
963+
PSECURITY_DESCRIPTOR WlScreenSaverDesktopSecurityDescriptor = NULL;
964964
BOOL ret = FALSE;
965965

966966
if (!CreateWinstaSecurity(&WlWinstaSecurityDescriptor))
@@ -1110,23 +1110,17 @@ CreateWindowStationAndDesktops(
11101110
CloseWindowStation(Session->InteractiveWindowStation);
11111111
Session->InteractiveWindowStation = NULL;
11121112
}
1113-
if (WlWinstaSecurityDescriptor)
1114-
{
1115-
RtlFreeHeap(RtlGetProcessHeap(), 0, WlWinstaSecurityDescriptor);
1116-
}
1117-
if (WlApplicationDesktopSecurityDescriptor)
1118-
{
1119-
RtlFreeHeap(RtlGetProcessHeap(), 0, WlApplicationDesktopSecurityDescriptor);
1120-
}
1121-
if (WlWinlogonDesktopSecurityDescriptor)
1122-
{
1123-
RtlFreeHeap(RtlGetProcessHeap(), 0, WlWinlogonDesktopSecurityDescriptor);
1124-
}
1125-
if (WlScreenSaverDesktopSecurityDescriptor)
1126-
{
1127-
RtlFreeHeap(RtlGetProcessHeap(), 0, WlScreenSaverDesktopSecurityDescriptor);
1128-
}
11291113
}
11301114

1115+
/* Free security descriptors regardless of success or failure */
1116+
if (WlWinstaSecurityDescriptor)
1117+
RtlFreeHeap(RtlGetProcessHeap(), 0, WlWinstaSecurityDescriptor);
1118+
if (WlApplicationDesktopSecurityDescriptor)
1119+
RtlFreeHeap(RtlGetProcessHeap(), 0, WlApplicationDesktopSecurityDescriptor);
1120+
if (WlWinlogonDesktopSecurityDescriptor)
1121+
RtlFreeHeap(RtlGetProcessHeap(), 0, WlWinlogonDesktopSecurityDescriptor);
1122+
if (WlScreenSaverDesktopSecurityDescriptor)
1123+
RtlFreeHeap(RtlGetProcessHeap(), 0, WlScreenSaverDesktopSecurityDescriptor);
1124+
11311125
return ret;
11321126
}

0 commit comments

Comments
 (0)