From: Mateusz Moscicki Date: Wed, 12 Sep 2018 10:36:37 +0000 (+0200) Subject: Fix Coverity warnings: #1020601 #1020599 #1020595 #1020587 X-Git-Tag: accepted/tizen/unified/20180917.041311~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=974bd2a0431e1369e032ccb5b7cdab5d9a8932da;p=platform%2Fcore%2Fsystem%2Fcrash-worker.git Fix Coverity warnings: #1020601 #1020599 #1020595 #1020587 Change-Id: I6cd513db97ad4f67f259f11e088be3e68c8dc319 --- diff --git a/src/crash-stack/crash-stack.c b/src/crash-stack/crash-stack.c index 99f60b3..bf1cd38 100644 --- a/src/crash-stack/crash-stack.c +++ b/src/crash-stack/crash-stack.c @@ -118,6 +118,7 @@ static int __get_registers_fd(pid_t pid, int fd) struct elf_prstatus *prstatus = NULL; ///< NT_PRSTATUS of the failed process size_t size = 0; char *registers = _crash_stack_get_memory_for_registers(&size); + int ret = -1; if (NULL == registers) { _E("Cannot get memory for registers (not implemented for this architecture"); @@ -130,12 +131,14 @@ static int __get_registers_fd(pid_t pid, int fd) if (prstatus == MAP_FAILED) return -1; - if (prstatus->pr_pid != pid) - return -1; + if (prstatus->pr_pid == pid) { + memcpy(registers, prstatus->pr_reg, size); + ret = 0; + } - memcpy(registers, prstatus->pr_reg, size); + munmap(prstatus, sizeof(struct elf_prstatus)); - return 0; + return ret; } /** diff --git a/src/crash-stack/mem_map.c b/src/crash-stack/mem_map.c index 3a0d463..e3c48f5 100644 --- a/src/crash-stack/mem_map.c +++ b/src/crash-stack/mem_map.c @@ -376,7 +376,7 @@ static int mem_region_map_file(struct mem_region *region) region->data_head->data = data; region->data_head->length = length; - region->data_index = malloc(sizeof(struct mem_data_chunk**)); + region->data_index = malloc(sizeof(struct mem_data_chunk*)); if (region->data_index == NULL){ _E("Unable to allocate memory:%m"); free(region->data_head); @@ -401,7 +401,7 @@ static int mem_region_init_vdso(struct mem_region *region) if ((region->data_head->data = (char *)get_vdso()) == NULL) return -1; - region->data_index = malloc(sizeof(struct mem_data_chunk**)); + region->data_index = malloc(sizeof(struct mem_data_chunk*)); if (region->data_index == NULL) { _E("Unable to allocate memory:%m"); return -1; @@ -425,7 +425,7 @@ static int mem_region_init_vsyscall(struct mem_region *region) region->data_head->start = region->start; region->data_head->data = (char *)VSYSCALL_START; region->data_head->length = region->length; - region->data_index = malloc(sizeof(struct mem_data_chunk**)); + region->data_index = malloc(sizeof(struct mem_data_chunk*)); if (region->data_index == NULL) { _E("Unable to allocate memory:%m"); return -1;