Skip to content

Commit ec96440

Browse files
committed
Preserve the Windows GetLastError error in HandleOrInvalid.
This ports the fix from rust-lang/rust#95158 to io-lifetimes.
1 parent 98af013 commit ec96440

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/types.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ impl TryFrom<HandleOrInvalid> for OwnedHandle {
497497
fn try_from(handle_or_invalid: HandleOrInvalid) -> Result<Self, ()> {
498498
let raw = handle_or_invalid.0;
499499
if raw == INVALID_HANDLE_VALUE {
500+
// Don't call `CloseHandle`; it'd be harmless, except that it could
501+
// overwrite the `GetLastError` error.
502+
forget(handle_or_invalid);
503+
500504
Err(())
501505
} else {
502506
Ok(OwnedHandle { handle: raw })
@@ -512,6 +516,10 @@ impl TryFrom<HandleOrNull> for OwnedHandle {
512516
fn try_from(handle_or_null: HandleOrNull) -> Result<Self, ()> {
513517
let raw = handle_or_null.0;
514518
if raw.is_null() {
519+
// Don't call `CloseHandle`; it'd be harmless, except that it could
520+
// overwrite the `GetLastError` error.
521+
forget(handle_or_null);
522+
515523
Err(())
516524
} else {
517525
Ok(OwnedHandle { handle: raw })

0 commit comments

Comments
 (0)