summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 04:38:08 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 04:38:08 +0000
commitfa69f28eb5cdca123bddc46029e63584daaf7897 (patch)
treed5410666f98d1fbd3c915169c40e5591046d24e5 /io.c
parent0412ddfd24f806b8d1dd88a367f21684b30e5fd0 (diff)
downloadruby-fa69f28eb5cdca123bddc46029e63584daaf7897.tar.gz
* io.c (fptr_finalize): must not use FILE after fclose().
[ruby-dev:24985] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7409 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/io.c b/io.c
index 649f272906..0cd715798c 100644
--- a/io.c
+++ b/io.c
@@ -1944,22 +1944,29 @@ fptr_finalize(fptr, noraise)
if (fptr->f2) {
f2 = fileno(fptr->f2);
- while (n2 = 0, fclose(fptr->f2) < 0) {
+ while (n2 = 0, fflush(fptr->f2) < 0) {
n2 = errno;
if (!rb_io_wait_writable(f2)) {
break;
}
if (!fptr->f2) break;
}
+ if (fclose(fptr->f2) < 0 && n2 == 0) {
+ n2 = errno;
+ }
fptr->f2 = 0;
}
if (fptr->f) {
f1 = fileno(fptr->f);
- while (n1 = 0, fclose(fptr->f) < 0) {
+ if ((f2 == -1) && (fptr->mode & FMODE_WBUF)) {
+ while (n1 = 0, fflush(fptr->f) < 0) {
+ n1 = errno;
+ if (!rb_io_wait_writable(f1)) break;
+ if (!fptr->f) break;
+ }
+ }
+ if (fclose(fptr->f) < 0 && n1 == 0) {
n1 = errno;
- if (f2 != -1 || !(fptr->mode & FMODE_WBUF)) break;
- if (!rb_io_wait_writable(f1)) break;
- if (!fptr->f) break;
}
fptr->f = 0;
if (n1 == EBADF && f1 == f2) {