Fix static analysis issue 21/318621/4
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 21 Jan 2025 07:26:32 +0000 (16:26 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Mon, 3 Feb 2025 01:53:24 +0000 (10:53 +0900)
Fix a resource leak.

Change-Id: Iebcd80b4fe4690dcbc160fadd9971e6c16ff768e
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/rsc-slice/pkg_rsc_slice.c

index 6c24aa21b43b5bbe7d049ba2dca6c267fee33f3c..c9996765822a2245b256904fcae30bfa53076553 100644 (file)
@@ -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)