diff options
author | Richard Henderson <richard.henderson@linaro.org> | 2024-02-26 17:03:19 -1000 |
---|---|---|
committer | Richard Henderson <richard.henderson@linaro.org> | 2024-02-29 08:48:02 -1000 |
commit | 106f8da6643634f141b39198576156a4c5bd6e60 (patch) | |
tree | 01ecfa4463dd9201f955da0e5830b4a336d5164d | |
parent | ccb6f3eee0f746961f95e9956fa20decd1f46da3 (diff) | |
download | qemu-106f8da6643634f141b39198576156a4c5bd6e60.zip qemu-106f8da6643634f141b39198576156a4c5bd6e60.tar.gz qemu-106f8da6643634f141b39198576156a4c5bd6e60.tar.bz2 |
linux-user/elfload: Open core file after vma_init
Swap the ordering of vma_init and open. This will be necessary
for further changes, and adjusts the error cleanup path. Narrow
the scope of corefile, as the variable can be freed immediately
after use in open().
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
-rw-r--r-- | linux-user/elfload.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 39d9ef9..877799e 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -4625,7 +4625,6 @@ static int elf_core_dump(int signr, const CPUArchState *env) const CPUState *cpu = env_cpu((CPUArchState *)env); const TaskState *ts = (const TaskState *)cpu->opaque; struct vm_area_struct *vma = NULL; - g_autofree char *corefile = NULL; struct elf_note_info info; struct elfhdr elf; struct elf_phdr phdr; @@ -4644,12 +4643,6 @@ static int elf_core_dump(int signr, const CPUArchState *env) return 0; } - corefile = core_dump_filename(ts); - - if ((fd = open(corefile, O_WRONLY | O_CREAT, - S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) < 0) - return (-errno); - /* * Walk through target process memory mappings and * set up structure containing this information. After @@ -4657,6 +4650,15 @@ static int elf_core_dump(int signr, const CPUArchState *env) */ vma_init(&mm); + { + g_autofree char *corefile = core_dump_filename(ts); + fd = open(corefile, O_WRONLY | O_CREAT, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + } + if (fd < 0) { + goto out; + } + walk_memory_regions(&mm, vma_walker); segs = vma_get_mapping_count(&mm); |