-
Notifications
You must be signed in to change notification settings - Fork 333
Fix descriptor leaks in win32 fstat implementation #329
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
Conversation
contrib/win32/win32compat/fileio.c
Outdated
debug4("fstat - pio:%p", pio); | ||
if (fd == -1) { | ||
errno = EOTHER; | ||
CloseHandle(dup_handle); |
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.
Fix indentation. You also need to sign the contributor agreement.
@@ -769,14 +769,24 @@ fileio_write(struct w32_io* pio, const void *buf, size_t max_bytes) | |||
int | |||
fileio_fstat(struct w32_io* pio, struct _stat64 *buf) | |||
{ | |||
int fd = _open_osfhandle((intptr_t)pio->handle, 0); | |||
HANDLE dup_handle = 0; | |||
if (!DuplicateHandle(GetCurrentProcess(), pio->handle, GetCurrentProcess(), &dup_handle, 0, |
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.
I don't think we need to duplicate handle here..
when you do _open_osfhandle it will return the c run-time file descriptor. If you close the c run-time file descriptor then it shouldn't have any impact on the os handle (pio->handle).
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.
According to the docs for _open_osfhandle, _close will close the underlying handle:
"To close a file opened with , call _close. The underlying handle is also closed by a call to _close, so it is not necessary to call the Win32 function CloseHandle on the original handle"
Though I'm not an expert in these APIs.
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.
My bad, I didn't read the msdn documentation properly.. You are right.
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.
.
I've signed the CLA. |
fixes:
PowerShell/Win32-OpenSSH#1209