-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[GITHUB-1042] c.s.j.p.WindowUtils.W32WindowUtils.getProcessFilePath does not close process handle #1043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[GITHUB-1042] c.s.j.p.WindowUtils.W32WindowUtils.getProcessFilePath does not close process handle #1043
Conversation
…oes not close process handle
895346d
to
2933a8b
Compare
if(Kernel32.INSTANCE.GetLastError() != WinNT.ERROR_ACCESS_DENIED) { | ||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); | ||
} else { | ||
// Ignore windows, that can't be accessed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to swallow any other unexpected error and return an incorrect result! Also I don't understand the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it does not. Line 1290 is entered if GetLastError
is not ERROR_ACCESS_DENIED
, so any other error is raised as a Win32Exception
. Before and after the change trying to access a process we don't have access to, will return the empty string.
throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); | ||
} else { | ||
// ignore invalid handles | ||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. The exception should be thrown on any other error, the previous code was correct IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my previous reply. What is important: calling Native.toString(filePath).trim()
on an initialized char[]
(all \0
) will result in the empty string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks. Maybe I should question the original implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean, that the function(s) should not return the empty string in case of an error? Yeah, I thought about "fixing" that, but I decided against it, as it basically became API by convention.
There are other thinks I would change looking at it - seeing a HWND
in a common class is suspicious.
…