From b589983aa6e57fee5b0b6158c04e066e730e19ae Mon Sep 17 00:00:00 2001 From: igerasim Date: Mon, 30 Jul 2018 17:10:28 -0700 Subject: [PATCH] 8207145: (fs) Native memory leak in WindowsNativeDispatcher.LookupPrivilegeValue0 Reviewed-by: alanb --- src/windows/classes/sun/nio/fs/WindowsSecurity.java | 9 +++++---- src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/windows/classes/sun/nio/fs/WindowsSecurity.java b/src/windows/classes/sun/nio/fs/WindowsSecurity.java index 1ceb570f1..13f28cb47 100644 --- a/src/windows/classes/sun/nio/fs/WindowsSecurity.java +++ b/src/windows/classes/sun/nio/fs/WindowsSecurity.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -102,9 +102,8 @@ class WindowsSecurity { final boolean stopImpersontating = impersontating; final boolean needToRevert = elevated; - return new Privilege() { - @Override - public void drop() { + return () -> { + try { if (token != 0L) { try { if (stopImpersontating) @@ -118,6 +117,8 @@ class WindowsSecurity { CloseHandle(token); } } + } finally { + LocalFree(pLuid); } }; } diff --git a/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c b/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c index 8075d0467..0a18e0b60 100644 --- a/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c +++ b/src/windows/native/sun/nio/fs/WindowsNativeDispatcher.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1074,8 +1074,11 @@ Java_sun_nio_fs_WindowsNativeDispatcher_LookupPrivilegeValue0(JNIEnv* env, if (pLuid == NULL) { JNU_ThrowInternalError(env, "Unable to allocate LUID structure"); } else { - if (LookupPrivilegeValueW(NULL, lpName, pLuid) == 0) + if (LookupPrivilegeValueW(NULL, lpName, pLuid) == 0) { + LocalFree(pLuid); throwWindowsException(env, GetLastError()); + return (jlong)0; + } } return ptr_to_jlong(pLuid); } -- GitLab