Release 6.5.17: Fix resource leaks 59/256259/4 accepted/tizen/unified/20210401.105943 submit/tizen/20210331.120928
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Wed, 31 Mar 2021 09:54:41 +0000 (11:54 +0200)
committerMateusz Moscicki <m.moscicki2@partner.samsung.com>
Wed, 31 Mar 2021 11:27:35 +0000 (13:27 +0200)
Change-Id: I3f4b6031baba78e3db2105020db3cbe24f3736e8

packaging/crash-worker.spec
src/bugreport-service/diagnostics/diagnostics_dump.c

index e088559..b50175a 100644 (file)
@@ -23,7 +23,7 @@
 
 Name:           crash-worker
 Summary:        Coredump handler and report generator for Tizen
-Version:        6.5.16
+Version:        6.5.17
 Release:        1
 Group:          Framework/system
 License:        Apache-2.0 and BSD-2-Clause and MIT
index 9a9c1dd..a5aea1b 100644 (file)
@@ -54,38 +54,50 @@ static bool get_reports_list(const char *path, struct report_file **list, size_t
                return false;
        }
 
+       char file_path[PATH_MAX];
+       bool ret = false;
+
        while ((ep = readdir(dp))) {
-               if (ep->d_type != 8)
+               if (ep->d_type != DT_REG)
                        continue;
                struct stat st;
-               char *file_path = NULL;
-               if (asprintf(&file_path, "%s/%s", path, ep->d_name) == -1) {
-                       _E("Memory allocation error: %m");
-                       return false;
+               int r = snprintf(file_path, sizeof file_path, "%s/%s", path, ep->d_name);
+               if (r == -1 || r >= sizeof file_path) {
+                       _E("Error while preparing report path: %m");
+                       goto out;
                }
                if (stat(file_path, &st) != 0) {
                        _E("Get stats about %s error: %m", path);
-                       return false;
+                       goto out;
                }
                struct tm t;
                if (localtime_r(&(st.st_ctim.tv_sec), &t) == NULL) {
                        _E("localtime_r error: %m");
-                       return false;
+                       goto out;
                }
 
                struct report_file *tmp_list = realloc(*list, sizeof(struct report_file)*(*list_count + 1));
-               if (tmp_list == NULL) {
+               char *fname = strdup(ep->d_name);
+               char *fpath = strdup(file_path);
+               if (tmp_list == NULL || fname == NULL || fpath == NULL) {
                        _E("Out of memory");
-                       return false;
+                       free(fname);
+                       free(fpath);
+                       free(tmp_list);
+                       goto out;
                }
+
                *list = tmp_list;
-               (*list)[*list_count].file_name = strdup(ep->d_name);
-               (*list)[*list_count].file_path = strdup(file_path);
+               (*list)[*list_count].file_name = fname;
+               (*list)[*list_count].file_path = fpath;
                (*list)[*list_count].ctime = st.st_ctim;
                (*list_count)++;
        }
+
+       ret = true;
+out:
        closedir(dp);
-       return true;
+       return ret;
 }
 
 static void free_record(struct report_file *record)