chiark / gitweb /
util: avoid double close of fd
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Wed, 8 Oct 2014 21:57:32 +0000 (23:57 +0200)
committerThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Wed, 8 Oct 2014 22:19:57 +0000 (00:19 +0200)
We could end with a double close if we close the fd loop and flush_fd
fails. That would make us goto fail and there we close the fd once
again. This patch sets the fd to the return value for safe_close: -1
A fd with negative value will be ignored by the next call to
safe_close.

CID#996223

src/shared/util.c

index bbd9bd11d6515205fd59d3d5f4120e6a099e335e..5f6249eb045d2fbb938af32e135a6811695f5c77 100644 (file)
@@ -2074,7 +2074,7 @@ int acquire_terminal(
                  * ended our handle will be dead. It's important that
                  * we do this after sleeping, so that we don't enter
                  * an endless loop. */
-                safe_close(fd);
+                fd = safe_close(fd);
         }
 
         safe_close(notify);