From: Adam Sitnik Date: Thu, 24 Jun 2021 10:38:53 +0000 (+0200) Subject: get last error before calling a method that might fail as well (#54667) X-Git-Tag: submit/tizen/20210909.063632~612 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72deae88e543b815339a7ba5a3d83a649e90b555;p=platform%2Fupstream%2Fdotnet%2Fruntime.git get last error before calling a method that might fail as well (#54667) --- diff --git a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs index 7a13a80..40c1e18 100644 --- a/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/Microsoft/Win32/SafeHandles/SafeFileHandle.Unix.cs @@ -44,8 +44,8 @@ namespace Microsoft.Win32.SafeHandles if (handle.IsInvalid) { - handle.Dispose(); Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo(); + handle.Dispose(); // If we fail to open the file due to a path not existing, we need to know whether to blame // the file itself or its directory. If we're creating the file, then we blame the directory, @@ -70,8 +70,9 @@ namespace Microsoft.Win32.SafeHandles Interop.Sys.FileStatus status; if (Interop.Sys.FStat(handle, out status) != 0) { + Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo(); handle.Dispose(); - throw Interop.GetExceptionForIoErrno(Interop.Sys.GetLastErrorInfo(), path); + throw Interop.GetExceptionForIoErrno(error, path); } if ((status.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR) {