mirror of
https://github.com/PowerShell/openssh-portable.git
synced 2025-07-31 01:35:11 +02:00
Fix descriptor leaks in win32 fstat implementation (#329)
Fix descriptor leaks in win32 fstat implementation PowerShell/Win32-OpenSSH#1209 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"
This commit is contained in:
parent
8bb672aa4d
commit
ce3db0ee61
@ -769,14 +769,24 @@ fileio_write(struct w32_io* pio, const void *buf, size_t max_bytes)
|
|||||||
int
|
int
|
||||||
fileio_fstat(struct w32_io* pio, struct _stat64 *buf)
|
fileio_fstat(struct w32_io* pio, struct _stat64 *buf)
|
||||||
{
|
{
|
||||||
int fd = _open_osfhandle((intptr_t)pio->handle, 0);
|
HANDLE dup_handle = 0;
|
||||||
debug4("fstat - pio:%p", pio);
|
if (!DuplicateHandle(GetCurrentProcess(), pio->handle, GetCurrentProcess(), &dup_handle, 0,
|
||||||
if (fd == -1) {
|
TRUE, DUPLICATE_SAME_ACCESS)) {
|
||||||
errno = EOTHER;
|
errno = EOTHER;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _fstat64(fd, buf);
|
int fd = _open_osfhandle(dup_handle, 0);
|
||||||
|
debug4("fstat - pio:%p", pio);
|
||||||
|
if (fd == -1) {
|
||||||
|
CloseHandle(dup_handle);
|
||||||
|
errno = EOTHER;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = _fstat64(fd, buf);
|
||||||
|
_close(fd);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user