Mark channel closed before interrupting in Unix's OS_channel_closed.
authorTaylor R Campbell <campbell@mumble.net>
Tue, 13 Dec 2011 07:40:37 +0000 (07:40 +0000)
committerTaylor R Campbell <campbell@mumble.net>
Tue, 13 Dec 2011 07:40:37 +0000 (07:40 +0000)
Interruption may restart the primitive that called it, which will
choke on a bad file descriptor.

src/microcode/uxio.c

index 353620709e48825e428cfbc32559a316760d4bb2..729f009f3ae74475fa958809e673f42fa8685ff4 100644 (file)
@@ -124,13 +124,14 @@ OS_channel_close (Tchannel channel)
 {
   if (! (CHANNEL_INTERNAL (channel)))
     {
-      if (0 > (UX_close (CHANNEL_DESCRIPTOR (channel))))
+      int status = (UX_close (CHANNEL_DESCRIPTOR (channel)));
+      MARK_CHANNEL_CLOSED (channel);
+      if (status < 0)
        switch (errno)
          {
          case EINTR:   deliver_pending_interrupts ();                  break;
          case EBADF:   error_system_call (errno, syscall_close);       break;
          }
-      MARK_CHANNEL_CLOSED (channel);
     }
 }