Fix Coverity warnings: #1020601 #1020599 #1020595 #1020587 08/189008/5
authorMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 12 Sep 2018 10:36:37 +0000 (12:36 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Thu, 13 Sep 2018 09:45:44 +0000 (11:45 +0200)
Change-Id: I6cd513db97ad4f67f259f11e088be3e68c8dc319

src/crash-stack/crash-stack.c
src/crash-stack/mem_map.c

index 99f60b3..bf1cd38 100644 (file)
@@ -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;
 }
 
 /**
index 3a0d463..e3c48f5 100644 (file)
@@ -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;