summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2016-10-24 16:16:06 -0400
committerColin Walters <walters@verbum.org>2016-10-27 13:30:11 -0400
commitabd37a4790f86f53bfb442e6d80e1710f50bff92 (patch)
tree97b770cfe49861751abb9c8e439227b5f4b46aa0
parent7d2f577d76eeb83a6f7a914a7acd3d277d4cbe7c (diff)
downloadlibglnx-abd37a4790f86f53bfb442e6d80e1710f50bff92.tar.gz
dirfd: Set initialized flag for iters
And use it when deinitializing, to avoid calling `closedir(NULL)`. In practice, this doesn't matter, because `closedir` *does* handle `NULL` in glibc. However, I'm playing with the GCC `-fsanitize=undefined`, and it aborts because `closedir` is tagged as requiring a non-`NULL` pointer.
-rw-r--r--glnx-dirfd.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/glnx-dirfd.c b/glnx-dirfd.c
index 95d7fe1..3a02bb0 100644
--- a/glnx-dirfd.c
+++ b/glnx-dirfd.c
@@ -142,6 +142,7 @@ glnx_dirfd_iterator_init_take_fd (int dfd,
real_dfd_iter->fd = dfd;
real_dfd_iter->d = d;
+ real_dfd_iter->initialized = TRUE;
ret = TRUE;
out:
@@ -169,6 +170,7 @@ glnx_dirfd_iterator_next_dent (GLnxDirFdIterator *dfd_iter,
GLnxRealDirfdIterator *real_dfd_iter = (GLnxRealDirfdIterator*) dfd_iter;
g_return_val_if_fail (out_dent, FALSE);
+ g_return_val_if_fail (dfd_iter->initialized, FALSE);
if (g_cancellable_set_error_if_cancelled (cancellable, error))
goto out;
@@ -250,6 +252,8 @@ glnx_dirfd_iterator_clear (GLnxDirFdIterator *dfd_iter)
{
GLnxRealDirfdIterator *real_dfd_iter = (GLnxRealDirfdIterator*) dfd_iter;
/* fd is owned by dfd_iter */
+ if (!real_dfd_iter->initialized)
+ return;
(void) closedir (real_dfd_iter->d);
real_dfd_iter->initialized = FALSE;
}