ntdll: Avoid leaking the previous environment in RtlSetCurrentEnvironment().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2020-05-06 09:40:27 -05:00 committed by Alexandre Julliard
parent d98b87a317
commit e012bd5811

View file

@ -996,14 +996,21 @@ NTSTATUS WINAPI RtlQueryEnvironmentVariable_U(PWSTR env,
*/
void WINAPI RtlSetCurrentEnvironment(PWSTR new_env, PWSTR* old_env)
{
WCHAR *prev;
TRACE("(%p %p)\n", new_env, old_env);
RtlAcquirePebLock();
if (old_env) *old_env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
prev = NtCurrentTeb()->Peb->ProcessParameters->Environment;
NtCurrentTeb()->Peb->ProcessParameters->Environment = new_env;
RtlReleasePebLock();
if (old_env)
*old_env = prev;
else
RtlDestroyEnvironment( prev );
}