From 0e0a644bf75b144faa007dd479e4d7e79c06c37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sj=C3=B6lund?= Date: Sat, 7 Oct 2023 09:53:18 +0200 Subject: [PATCH] read-file.c: restore errno after successful fclose() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to errno(3) a function that succeeds is allowed to change errno. Signed-off-by: Erik Sjölund --- tools/read-file.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/read-file.c b/tools/read-file.c index ee35a935..5b7919cd 100644 --- a/tools/read-file.c +++ b/tools/read-file.c @@ -123,10 +123,9 @@ char *read_file(const char *path, size_t *length) if (buf) { save_errno = errno; free(buf); + buf = NULL; } - errno = save_errno; - return NULL; } - + errno = save_errno; return buf; }