From: Sangyoon Jang Date: Tue, 21 Jan 2025 07:26:32 +0000 (+0900) Subject: Fix static analysis issue X-Git-Tag: accepted/tizen/unified/20250204.110444~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=882da24e2896e519547e199416bc22a5ff0c1c7c;p=platform%2Fcore%2Fappfw%2Fpkgmgr-tool.git Fix static analysis issue Fix a resource leak. Change-Id: Iebcd80b4fe4690dcbc160fadd9971e6c16ff768e Signed-off-by: Sangyoon Jang --- diff --git a/src/rsc-slice/pkg_rsc_slice.c b/src/rsc-slice/pkg_rsc_slice.c index 6c24aa2..c999676 100644 --- a/src/rsc-slice/pkg_rsc_slice.c +++ b/src/rsc-slice/pkg_rsc_slice.c @@ -124,7 +124,7 @@ static void __print_usage() static void __del_file(GHashTable *valid_file_list, char *path) { - struct dirent **items; + struct dirent **items = NULL; struct stat fstat; char abs_path[1024] = {0, }; char cwd[1024] = {0, }; @@ -147,11 +147,11 @@ static void __del_file(GHashTable *valid_file_list, char *path) ret = snprintf(abs_path, 1024 - 1, "%s/%s", cwd, items[i]->d_name); if (ret < 0 || ret > 1024 -1 ) { printf("snprintf fail\n"); - return; + goto catch; } if (g_lstat(abs_path, &fstat) != 0) { printf("failed to get info[%s]\n", abs_path); - return; + goto catch; } if ((fstat.st_mode & S_IFDIR) == S_IFDIR) { __del_file(valid_file_list, abs_path); @@ -167,6 +167,13 @@ static void __del_file(GHashTable *valid_file_list, char *path) } } } + +catch: + if (items) { + for (i = 0; i < nitems; i++) + free(items[i]); + free(items); + } } static int __process_slice(rsc_tool_args *data)