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
commit9247eb133be595b10a901bf13bbd886f77bf0cbb (patch)
tree26c7433996cea1ed7da8c3832f55c33142143b45 /io.c
parent518c3a3479747b304d5e75b449f9377577a9d978 (diff)
* io.c (fptr_finalize): must not use FILE after fclose().
[ruby-dev:24985] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@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 1cce098..ba7f4b0 100644
--- a/io.c
+++ b/io.c
@@ -1810,22 +1810,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) {