diff --git a/tools/process_dump/dfx_elf.c b/tools/process_dump/dfx_elf.c index 70d7bd934ec7620b5822a17aca15b4c467871a43..b44f982013f8ddcd9da014dd8ebcca7a43061213 100644 --- a/tools/process_dump/dfx_elf.c +++ b/tools/process_dump/dfx_elf.c @@ -156,6 +156,9 @@ void CreateLoadInfo(DfxElfImage *image, uint64_t vaddr, uint64_t offset) } LoadInfo *info = (LoadInfo *)calloc(1, sizeof(LoadInfo)); + if (info == NULL) { + return; + } info->vaddr = vaddr; info->offset = offset; diff --git a/tools/process_dump/dfx_process.c b/tools/process_dump/dfx_process.c index 253fa97217367376b5e970cd8bf73c6c4353bfc7..433c9482c659dfbd299d60201a9f91042829f211 100644 --- a/tools/process_dump/dfx_process.c +++ b/tools/process_dump/dfx_process.c @@ -58,6 +58,8 @@ BOOL InitProcessWithKeyThread(DfxProcess **process, pid_t pid, DfxThread *keyThr (*process)->processName = calloc(1, NAME_LEN); if ((*process)->processName == NULL) { DfxLogWarn("Fail to alloc processName."); + free(*process); + *process = NULL; return FALSE; } diff --git a/tools/process_dump/dfx_unwind_remote.c b/tools/process_dump/dfx_unwind_remote.c index d1783befcf8ed138d6aaac97891b954f99c0bcf7..c61f0971b847959e44da1c65cd655c6f731eeb1c 100644 --- a/tools/process_dump/dfx_unwind_remote.c +++ b/tools/process_dump/dfx_unwind_remote.c @@ -61,15 +61,22 @@ BOOL UnwindThread(DfxProcess *process, DfxThread *thread) } unw_addr_space_t as = unw_create_addr_space(&_UPT_accessors, 0); + if (as == NULL) { + return FALSE; + } + pid_t tid = thread->tid; void *context = _UPT_create(tid); if (context == NULL) { - DfxLogWarn("Fail to create context for %d.", tid); + unw_destroy_addr_space(as); return FALSE; } + unw_cursor_t cursor; if (unw_init_remote(&cursor, as, context) != 0) { DfxLogWarn("Fail to init cursor for remote unwind."); + _UPT_destroy(context); + unw_destroy_addr_space(as); return FALSE; } @@ -103,5 +110,6 @@ BOOL UnwindThread(DfxProcess *process, DfxThread *thread) index++; } while (unw_step(&cursor) > 0); _UPT_destroy(context); + unw_destroy_addr_space(as); return TRUE; }