[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: |
John W. Eaton |
Subject: |
Re: File Handle leak? Was: Octave/Win32 new binary package (2.9.12) |
Date: |
Tue, 5 Jun 2007 01:49:20 -0400 |
On 4-Jun-2007, Michael Goffioul wrote:
| On 6/4/07, Olli Saarela <address@hidden> wrote:
| > Benjamin Lindner wrote:
| > > A simple command like 'upper("a");' entered at the prompt increases
| > > the file handle count by 2 for every command.
|
| There was indeed a bug in octave code, where file handles were not closed
| properly. See patch below.
|
| Michael.
|
| Index: sysdep.cc
| ===================================================================
| RCS file: /cvs/octave/src/sysdep.cc,v
| retrieving revision 1.128
| diff -c -p -r1.128 sysdep.cc
| *** sysdep.cc 31 May 2007 19:39:12 -0000 1.128
| --- sysdep.cc 4 Jun 2007 14:59:45 -0000
| *************** same_file_internal (const std::string& f
| *** 269,274 ****
| --- 269,277 ----
| CloseHandle (hfile2);
| return false;
| }
| +
| + CloseHandle (hfile1);
| + CloseHandle (hfile2);
|
| return (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber
| && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh
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?
jwe