Fix some static analyzer issues 34/154434/1
authorSemun Lee <semun.lee@samsung.com>
Tue, 10 Oct 2017 07:53:05 +0000 (16:53 +0900)
committerSemun Lee <semun.lee@samsung.com>
Tue, 10 Oct 2017 07:53:05 +0000 (16:53 +0900)
- fix resource leak
- check return value properly

Change-Id: I9c3ab936cb6c84dbb664a6c41c74f48f5dab5067
Signed-off-by: Semun Lee <semun.lee@samsung.com>
src/delta.c
src/pkg_rsc_slice.c
src/pkg_upgrade.c

index 1218642..c105d4f 100644 (file)
@@ -192,14 +192,15 @@ void __create_diff_file(char *old_tpk_path, char *new_tpk_path)
        char message[MAX_MESSAGE_LEN];
 
        list_dir_old_tpk = __list_directory(old_tpk_path, old_tpk_path, list_dir_old_tpk);
-       list_dir_new_tpk = __list_directory(new_tpk_path, new_tpk_path, list_dir_new_tpk);
        if (list_dir_old_tpk == NULL) {
                printf("Could Not read %s\n", old_tpk_path);
                return;
        }
 
+       list_dir_new_tpk = __list_directory(new_tpk_path, new_tpk_path, list_dir_new_tpk);
        if (list_dir_new_tpk == NULL) {
                printf("Could Not read %s\n", new_tpk_path);
+               __free_g_list(list_dir_old_tpk);
                return;
        }
 
index 67b1093..e6d45c6 100644 (file)
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
+#include <errno.h>
 #include <unistd.h>
 #include <ctype.h>
 #include <getopt.h>
@@ -133,6 +134,7 @@ static void __del_file(char *path)
        char cwd[1024] = {0, };
        char *tmp = NULL;
        int nitems, i;
+       int ret;
 
        if (chdir(path) < 0) {
                printf("failed to chdir[%s]\n", path);
@@ -157,7 +159,11 @@ static void __del_file(char *path)
                        tmp = g_hash_table_lookup(valid_file_list, abs_path);
                        if (tmp == NULL) {
                                printf("deleting [%s]\n", abs_path);
-                               remove(abs_path);
+                               ret = remove(abs_path);
+                               if (ret == -1) {
+                                       printf("failed to remove [%s][%d]\n",
+                                               abs_path, errno);
+                               }
                        }
                }
        }
index aa3e790..ebbd787 100644 (file)
@@ -885,6 +885,13 @@ static int __process_rw_fota(const char *directory)
 
                        ret = pkgmgrinfo_compare_package_version(version,
                                        pkg_info->version, &compare);
+                       if (ret != PMINFO_R_OK) {
+                               _LOG("can not compare pkg version[%s]\n",
+                                       pkg_info->pkgid);
+                               pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
+                               continue;
+                       }
+
                        if (compare != PMINFO_VERSION_NEW) {
                                /* package version is not update on FOTA. */
                                _LOG("pkg is not updated\n");