Bug #2992

File operations leak file handles in Windows XP

Added by Pete Higgins almost 2 years ago. Updated 10 months ago.

[ruby-core:28833]
Status:Closed Start date:03/21/2010
Priority:Normal Due date:
Assignee:Usaku NAKAMURA % Done:

100%

Category:-
Target version:1.9.2
ruby -v:ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]

Description

Various operations on files leak file handles in Windows XP. In the two attached scripts, Task Manager will report ~30 open file handles for the ruby process at the first gets, then ~230 at the second gets.

This has only been reproducible in Windows XP. This behavior is not seen in Windows Vista or 7. 

More discussion of this issue occurred on the RubyInstaller mailing list in this thread: 
http://groups.google.com/group/rubyinstaller/browse_thread/thread/85ddec7241b4f0f7

test_md5.rb (272 Bytes) Pete Higgins, 03/21/2010 05:34 am

test_file_read.rb (415 Bytes) Pete Higgins, 03/21/2010 05:34 am

Associated revisions

Revision 27042
Added by Nobuyoshi Nakada almost 2 years ago

* win32/win32.c (rb_w32_{read,write}): fix handle leaks. based on a patch from Heesob Park in [ruby-core:28919]. [ruby-core:28833]

History

Updated by Heesob Park almost 2 years ago

After some inspection, I found this leakage is not file handle but event handle.
When ReadFile fails with EOF, it returns without closing event handle.

Here is a patch for trunck verion ruby 1.9.2dev (2010-03-24 trunk 27027)

--- win32.c     2010-03-24 11:24:43.149695643 +0900
+++ win32.c.new 2010-03-24 11:26:44.522700645 +0900
@@ -4887,6 +4887,7 @@
     if (!ReadFile((HANDLE)_osfhnd(fd), buf, size, &read, pol)) {
        err = GetLastError();
        if (err != ERROR_IO_PENDING) {
+           if(pol) CloseHandle(ol.hEvent);
            if (err == ERROR_ACCESS_DENIED)
                errno = EBADF;
            else if (err == ERROR_BROKEN_PIPE || err == ERROR_HANDLE_EOF) {

Updated by Yuki Sonoda almost 2 years ago

  • Assignee set to Usaku NAKAMURA

Updated by Yuki Sonoda almost 2 years ago

  • Target version set to 1.9.2

Updated by Nobuyoshi Nakada almost 2 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
This issue was solved with changeset r27042.
Pete, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

Also available in: Atom PDF