octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File Handle leak? Was: Octave/Win32 new binary package (2.9.12)


From: Michael Goffioul
Subject: Re: File Handle leak? Was: Octave/Win32 new binary package (2.9.12)
Date: Tue, 5 Jun 2007 09:22:40 +0200

On 6/5/07, John W. Eaton <address@hidden> wrote:
I rewrote it like this:

 bool retval = false;

 // Windows native code
 // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx

 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 (hfile2 != INVALID_HANDLE_VALUE)
       {
         BY_HANDLE_FILE_INFORMATION hfi1;
         BY_HANDLE_FILE_INFORMATION hfi2;

         if (GetFileInformationByHandle (hfile1, &hfi1)
             && GetFileInformationByHandle (hfile2, &hfi2))

           retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber
                     && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh
                     && hfi1.nFileIndexLow == hfi2.nFileIndexLow);

         CloseHandle (hfile2);
       }

     CloseHandle (hfile1);
   }

 return retval;


Is that OK?

Yes.

Michael.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]