In article <976341212.073895.22113.nullmailer / ev.netlab.zetabits.com>,
  matz / zetabits.com (Yukihiro Matsumoto) writes:

> まつもと ゆきひろです
> 
> In message "[ruby-ext:01446] Re: Unexpected Error Exit when using Ruby/Gtk"
>     on 00/12/08, Yasushi Shoji <yashi / yashi.com> writes:
> 
> |もしかして、rubyの bug?
> 
> それバグなのかなあ。

思うに、

  % ruby -e ''

とするだけでも fclose を呼び出すのは ruby の問題ともいえる気がします。

% gdb ./ruby
GNU gdb 4.18
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-unknown-freebsd"...
(gdb) break fclose
Breakpoint 1 at 0x804fda8
(gdb) run -e ''
Starting program: /usr/home/akr/src/ruby/ruby/./ruby -e ''
Breakpoint 1 at 0x281768d9

Breakpoint 1, 0x281768d9 in fclose () from /usr/lib/libc.so.4
(gdb) where
#0  0x281768d9 in fclose () from /usr/lib/libc.so.4
#1  0x8069829 in fptr_finalize (fptr=0x8119a60) at io.c:1009
#2  0x8069875 in rb_io_fptr_finalize (fptr=0x8119a60) at io.c:1027
#3  0x8065699 in rb_gc_call_finalizer_at_exit () at gc.c:1248
#4  0x805160d in ruby_finalize () at eval.c:1127
#5  0x80516be in ruby_stop (ex=0) at eval.c:1149
#6  0x80517ac in ruby_run () at eval.c:1172
#7  0x805018e in main (argc=3, argv=0xbfbff3c4, envp=0xbfbff3d4) at main.c:50
#8  0x8050105 in _start ()
(gdb) up   
#1  0x8069829 in fptr_finalize (fptr=0x8119a60) at io.c:1009
1009            fclose(fptr->f);
(gdb) print fptr->f
$1 = (FILE *) 0x80c9bd0
(gdb) print *fptr->f
$2 = {_p = 0x0, _r = 0, _w = 0, _flags = 10, _file = 2, _bf = {_base = 0x0, _size = 0}, _lbfsize = 0, _cookie = 0x80c9bd0, 
  _close = 0x281882a4 <__sclose>, _read = 0x281881b4 <__sread>, _seek = 0x28188250 <__sseek>, 
  _write = 0x28188200 <__swrite>, _ub = {_base = 0x0, _size = 0}, _up = 0x0, _ur = 0, _ubuf = "\000\000", _nbuf = "", 
  _lb = {_base = 0x0, _size = 0}, _blksize = 0, _offset = 0}
(gdb) print fptr->f->_file
$3 = 2
(gdb) c
Continuing.

Breakpoint 1, 0x281768d9 in fclose () from /usr/lib/libc.so.4
(gdb) up
#1  0x8069829 in fptr_finalize (fptr=0x8119a20) at io.c:1009
1009            fclose(fptr->f);
(gdb) print fptr->f->_file
$4 = 1
(gdb) c
Continuing.

Breakpoint 1, 0x281768d9 in fclose () from /usr/lib/libc.so.4
(gdb) up
#1  0x8069829 in fptr_finalize (fptr=0x81199e0) at io.c:1009
1009            fclose(fptr->f);
(gdb) print fptr->f->_file
$5 = 0
(gdb) c
Continuing.

Program exited normally.

ちなみに、Solaris だと open で 2以下は割り当てられないので、(確認して
ませんがソケットにも同じような対策がしてあるとすれば) X は 3以上を使う
ので問題が発覚しなかったような気もしますね。

とりあえず、stdin, stdout, stderr だったら fclose しない、という条件判
断を入れてみるというのはいかがでしょうか。
-- 
[田中 哲][たなか あきら][Tanaka Akira]
「くっだらないコト聞いちゃったねー$(C⊇ ごっめーん$(C⊇」
  (魔法使い養成専門 マジックスター学院 2, 南澤ミヅキ)