]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
linux-user/elfload: Latch errno before cleanup in elf_core_dump
authorRichard Henderson <richard.henderson@linaro.org>
Tue, 27 Feb 2024 02:58:02 +0000 (16:58 -1000)
committerRichard Henderson <richard.henderson@linaro.org>
Thu, 29 Feb 2024 18:48:02 +0000 (08:48 -1000)
On the off-chance that one of the cleanup functions changes
errno, latch the errno that we want to return beforehand.

Flush errno to 0 upon success, rather than at the beginning.
No need to avoid negation of 0.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
linux-user/elfload.c

index 98b82b1a495dbb8f1a3e6738f821733d0912ca81..39d9ef9acc8feea4a23928793f73f7060a950298 100644 (file)
@@ -4634,8 +4634,7 @@ static int elf_core_dump(int signr, const CPUArchState *env)
     off_t offset = 0, data_offset = 0;
     int segs = 0;
     int fd = -1;
-
-    errno = 0;
+    int ret;
 
     if (prctl(PR_GET_DUMPABLE) == 0) {
         return 0;
@@ -4755,15 +4754,14 @@ static int elf_core_dump(int signr, const CPUArchState *env)
                 goto out;
         }
     }
+    errno = 0;
 
  out:
+    ret = -errno;
     free_note_info(&info);
     vma_delete(&mm);
-    (void) close(fd);
-
-    if (errno != 0)
-        return (-errno);
-    return (0);
+    close(fd);
+    return ret;
 }
 #endif /* USE_ELF_CORE_DUMP */