Mercurial > hg > octave-lyh
changeset 6691:c6ee6c342699
[project @ 2007-06-05 05:50:10 by jwe]
author | jwe |
---|---|
date | Tue, 05 Jun 2007 05:50:10 +0000 |
parents | fd242dccd221 |
children | 89b916a9eb61 |
files | src/ChangeLog src/sysdep.cc |
diffstat | 2 files changed, 29 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2007-06-05 John W. Eaton <jwe@octave.org> + + * sysdep.cc (same_file_internal) [OCTAVE_USE_WINDOWS_API]: + Avoid leaking file handles. + 2007-05-08 Michael Weitzel <michael.weitzel@uni-siegen.de> * DLD-FUNCTIONS/symrcm.cc: Fix for queuing error that might cause
--- a/src/sysdep.cc +++ b/src/sysdep.cc @@ -232,47 +232,38 @@ { #ifdef OCTAVE_USE_WINDOWS_API + bool retval = false; + // Windows native code // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx - HANDLE hfile1; - HANDLE hfile2; - - BY_HANDLE_FILE_INFORMATION hfi1; - BY_HANDLE_FILE_INFORMATION hfi2; - - hfile1 = CreateFile (file1.c_str (), 0, FILE_SHARE_READ, 0, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE hfile1 = CreateFile (file1.c_str (), 0, FILE_SHARE_READ, 0, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + + if (hfile1 != INVALID_HANDLE_VALUE) + { + HANDLE hfile2 = CreateFile (file2.c_str (), 0, FILE_SHARE_READ, 0, + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if (hfile1 == INVALID_HANDLE_VALUE) - return false; + if (hfile2 != INVALID_HANDLE_VALUE) + { + BY_HANDLE_FILE_INFORMATION hfi1; + BY_HANDLE_FILE_INFORMATION hfi2; + + if (GetFileInformationByHandle (hfile1, &hfi1) + && GetFileInformationByHandle (hfile2, &hfi2)) - hfile2 = CreateFile (file2.c_str (), 0, FILE_SHARE_READ, 0, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber + && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh + && hfi1.nFileIndexLow == hfi2.nFileIndexLow); - if (hfile2 == INVALID_HANDLE_VALUE) - { + CloseHandle (hfile2); + } + CloseHandle (hfile1); - return false; } - - if (! GetFileInformationByHandle (hfile1, &hfi1)) - { - CloseHandle (hfile1); - CloseHandle (hfile2); - return false; - } - - if (! GetFileInformationByHandle (hfile2, &hfi2)) - { - CloseHandle (hfile1); - CloseHandle (hfile2); - return false; - } - - return (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber - && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh - && hfi1.nFileIndexLow == hfi2.nFileIndexLow); + + return retval; #else