From 9f9964239e21d2e70df5ba1bf75fbdcc3c507cf0 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Sun, 8 May 2022 20:32:52 +0100 Subject: [PATCH] Ensure logging doesn't affect errno --- src/snmalloc/pal/pal_posix.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/snmalloc/pal/pal_posix.h b/src/snmalloc/pal/pal_posix.h index f71755d..58b3c1f 100644 --- a/src/snmalloc/pal/pal_posix.h +++ b/src/snmalloc/pal/pal_posix.h @@ -163,6 +163,9 @@ namespace snmalloc */ static void message(const char* const str) noexcept { + // We don't want logging to affect the errno behaviour of the program. + auto hold = KeepErrno(); + void* nl = const_cast("\n"); struct iovec iov[] = {{const_cast(str), strlen(str)}, {nl, 1}}; UNUSED(writev(STDERR_FILENO, iov, sizeof(iov) / sizeof(struct iovec)));