diff options
author | Colin Walters <walters@verbum.org> | 2017-09-11 17:17:12 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2017-09-12 09:43:05 -0400 |
commit | 9d995a362009ae01bca14c781e14d5623ad27cd6 (patch) | |
tree | ae1e1ba8b496b925c1c27fadd2127168565f9334 /glnx-fdio.c | |
parent | 806bb46e054d2c960f129503dddf724383700899 (diff) | |
download | libglnx-9d995a362009ae01bca14c781e14d5623ad27cd6.tar.gz |
fdio: Support taking ownership of tmpfile fd
While reading a strace I noticed a double close in the tests; this was because
we were missing an assignment to `-1` in the tests. However, let's make
supporting this clearer by explicitly supporting the fd being `-1` while still
setting the `initialized` variable to `FALSE`. We also add the `EBADF` assertion
checking.
Diffstat (limited to 'glnx-fdio.c')
-rw-r--r-- | glnx-fdio.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/glnx-fdio.c b/glnx-fdio.c index e8e2167..0046807 100644 --- a/glnx-fdio.c +++ b/glnx-fdio.c @@ -168,9 +168,11 @@ glnx_tmpfile_clear (GLnxTmpfile *tmpf) return; if (!tmpf->initialized) return; - if (tmpf->fd == -1) - return; - (void) close (tmpf->fd); + if (tmpf->fd != -1) + { + if (close (tmpf->fd) < 0) + g_assert (errno != EBADF); + } /* If ->path is set, we're likely aborting due to an error. Clean it up */ if (tmpf->path) { |