8207145: (fs) Native memory leak in WindowsNativeDispatcher.LookupPrivilegeValue0
authorigerasim
Thu, 12 Jul 2018 06:04:57 -0700
changeset 51043 6c449bdee4fa
parent 51042 f378705346bf
child 51044 68646e6522ca
child 51166 97f4558b287f
child 56830 5126a14ac51e
8207145: (fs) Native memory leak in WindowsNativeDispatcher.LookupPrivilegeValue0 Reviewed-by: alanb
src/java.base/windows/classes/sun/nio/fs/WindowsSecurity.java
src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c
--- a/src/java.base/windows/classes/sun/nio/fs/WindowsSecurity.java	Wed Jul 11 13:55:38 2018 -0400
+++ b/src/java.base/windows/classes/sun/nio/fs/WindowsSecurity.java	Thu Jul 12 06:04:57 2018 -0700
@@ -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 @@
         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 @@
                         CloseHandle(token);
                     }
                 }
+            } finally {
+                LocalFree(pLuid);
             }
         };
     }
--- a/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c	Wed Jul 11 13:55:38 2018 -0400
+++ b/src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c	Thu Jul 12 06:04:57 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2017, 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
@@ -1043,8 +1043,11 @@
     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);
 }