summary refs log tree commit diff stats
path: root/contrib/elf2dmp/addrspace.c
diff options
context:
space:
mode:
authorSuraj Shirvankar <surajshirvankar@gmail.com>2023-10-03 14:45:14 +0200
committerPeter Maydell <peter.maydell@linaro.org>2023-10-19 14:32:13 +0100
commit2a052b4ee01b3c413cef2ef49cb780cde17d4ba1 (patch)
treeca659b30aacebc24516ffc9dcc9f38f3130ae4c5 /contrib/elf2dmp/addrspace.c
parent9ef2629712680e70cbf39d8b6cb1ec0e0e2e72fa (diff)
downloadfocaccia-qemu-2a052b4ee01b3c413cef2ef49cb780cde17d4ba1.tar.gz
focaccia-qemu-2a052b4ee01b3c413cef2ef49cb780cde17d4ba1.zip
contrib/elf2dmp: Use g_malloc(), g_new() and g_free()
QEMU coding style uses the glib memory allocation APIs, not
the raw libc malloc/free. Switch the allocation and free
calls in elf2dmp to use these functions (dropping the now-unneeded
checks for failure).

Signed-off-by: Suraj Shirvankar <surajshirvankar@gmail.com>
Message-id: 169753938460.23804.11418813007617535750-1@git.sr.ht
[PMM: also remove NULL checks from g_malloc() calls;
 beef up commit message]
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'contrib/elf2dmp/addrspace.c')
-rw-r--r--contrib/elf2dmp/addrspace.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c
index 64b5d680ad..6f608a517b 100644
--- a/contrib/elf2dmp/addrspace.c
+++ b/contrib/elf2dmp/addrspace.c
@@ -72,10 +72,7 @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf)
         }
     }
 
-    ps->block = malloc(sizeof(*ps->block) * ps->block_nr);
-    if (!ps->block) {
-        return 1;
-    }
+    ps->block = g_new(struct pa_block, ps->block_nr);
 
     for (i = 0; i < phdr_nr; i++) {
         if (phdr[i].p_type == PT_LOAD) {
@@ -97,7 +94,7 @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf)
 void pa_space_destroy(struct pa_space *ps)
 {
     ps->block_nr = 0;
-    free(ps->block);
+    g_free(ps->block);
 }
 
 void va_space_set_dtb(struct va_space *vs, uint64_t dtb)