From: Karol Lewandowski Date: Wed, 31 Mar 2021 09:54:41 +0000 (+0200) Subject: Release 6.5.17: Fix resource leaks X-Git-Tag: submit/tizen/20210331.120928^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a011325bbc4482145ee9aa5abc41df45f381d7cd;p=platform%2Fcore%2Fsystem%2Fcrash-worker.git Release 6.5.17: Fix resource leaks Change-Id: I3f4b6031baba78e3db2105020db3cbe24f3736e8 --- diff --git a/packaging/crash-worker.spec b/packaging/crash-worker.spec index e088559e..b50175a8 100644 --- a/packaging/crash-worker.spec +++ b/packaging/crash-worker.spec @@ -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 diff --git a/src/bugreport-service/diagnostics/diagnostics_dump.c b/src/bugreport-service/diagnostics/diagnostics_dump.c index 9a9c1dd1..a5aea1b6 100644 --- a/src/bugreport-service/diagnostics/diagnostics_dump.c +++ b/src/bugreport-service/diagnostics/diagnostics_dump.c @@ -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)