Skip to content

Commit 78f3c8a

Browse files
author
Ivan Gerasimov
committed
8207145: (fs) Native memory leak in WindowsNativeDispatcher.LookupPrivilegeValue0
Reviewed-by: alanb
1 parent 1c97626 commit 78f3c8a

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/java.base/windows/classes/sun/nio/fs/WindowsSecurity.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -102,9 +102,8 @@ static Privilege enablePrivilege(String priv) {
102102
final boolean stopImpersontating = impersontating;
103103
final boolean needToRevert = elevated;
104104

105-
return new Privilege() {
106-
@Override
107-
public void drop() {
105+
return () -> {
106+
try {
108107
if (token != 0L) {
109108
try {
110109
if (stopImpersontating)
@@ -118,6 +117,8 @@ else if (needToRevert)
118117
CloseHandle(token);
119118
}
120119
}
120+
} finally {
121+
LocalFree(pLuid);
121122
}
122123
};
123124
}

src/java.base/windows/native/libnio/fs/WindowsNativeDispatcher.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1043,8 +1043,11 @@ Java_sun_nio_fs_WindowsNativeDispatcher_LookupPrivilegeValue0(JNIEnv* env,
10431043
if (pLuid == NULL) {
10441044
JNU_ThrowInternalError(env, "Unable to allocate LUID structure");
10451045
} else {
1046-
if (LookupPrivilegeValueW(NULL, lpName, pLuid) == 0)
1046+
if (LookupPrivilegeValueW(NULL, lpName, pLuid) == 0) {
1047+
LocalFree(pLuid);
10471048
throwWindowsException(env, GetLastError());
1049+
return (jlong)0;
1050+
}
10481051
}
10491052
return ptr_to_jlong(pLuid);
10501053
}

0 commit comments

Comments
 (0)