diff options
author | Alexander Larsson <alexl@redhat.com> | 2016-03-10 23:12:07 +0100 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2016-03-10 23:12:07 +0100 |
commit | 69d8a597f768f811f7c924a784af834f637eeb20 (patch) | |
tree | dabddae6324058bf14c8397ce47b8810c8439927 | |
parent | 08ae6639e522e9b11765245fbecdbbe474ccde98 (diff) | |
download | libglnx-69d8a597f768f811f7c924a784af834f637eeb20.tar.gz |
Don't touch errno in glnx_fd_close
We're ignoring the result from the close, but it can still affect
errno, which is bad if you use this in functions that sets
errno, because errno can unexpectedly change after you've set it.
-rw-r--r-- | glnx-local-alloc.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/glnx-local-alloc.h b/glnx-local-alloc.h index af5af4b..f628b61 100644 --- a/glnx-local-alloc.h +++ b/glnx-local-alloc.h @@ -21,6 +21,7 @@ #pragma once #include <gio/gio.h> +#include <errno.h> G_BEGIN_DECLS @@ -195,13 +196,17 @@ GLNX_DEFINE_CLEANUP_FUNCTION0(GKeyFile*, glnx_local_keyfile_unref, g_key_file_un static inline void glnx_cleanup_close_fdp (int *fdp) { - int fd; + int fd, errsv; g_assert (fdp); fd = *fdp; if (fd != -1) - (void) close (fd); + { + errsv = errno; + (void) close (fd); + errno = errsv; + } } /** |