Add checking return value of library functions 80/179080/2
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Fri, 11 May 2018 16:30:34 +0000 (19:30 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 16 May 2018 09:09:53 +0000 (12:09 +0300)
Change-Id: If917ec91bda74c46b4b1007a2e907a546362e8d8
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
daemon/sys_stat.c
ui_viewer/ui_viewer_lib.c
ui_viewer/ui_viewer_utils.c

index 9d6cd18eef4f88bda81e50e16259820097fd0722..c31e8f953b60578b0af4539acc59ad0253e7e541 100644 (file)
@@ -990,6 +990,7 @@ static int parse_proc_smaps_file_bypid(char *path, proc_t *P)
 {
 #define MIN_SMAP_BLOCKLINE     50
 
+       int ret_val = -1;
        char path_smaps[PROCPATH_MAX];
        mapinfo_section_t map;
        FILE* fp;
@@ -1010,14 +1011,13 @@ static int parse_proc_smaps_file_bypid(char *path, proc_t *P)
        bool ret = save_request_to_tmpfile(path_smaps, tmp_path, tmp_suffixlen);
        if (!ret) {
                LOGE("Cannot save smaps to tmpfile\n");
-               return -1;
+               goto out;
        }
 
        fp = fopen(tmp_path, "r");
        if(fp == NULL){
-               LOGE("Open '%s'\n", tmp_path);
-               remove(tmp_path);
-               return -1;
+               LOGE("Cannot open '%s'\n", tmp_path);
+               goto remove_tmp_path;
        }
 
        while (read_mapinfo_section(fp, &map) == 0) {
@@ -1045,10 +1045,18 @@ static int parse_proc_smaps_file_bypid(char *path, proc_t *P)
        P->sh_mem_clean *= 1024;
        P->sh_mem_dirty *= 1024;
 
-       fclose(fp);
-       remove(tmp_path);
+       if (fclose(fp))
+               LOGE("Cannot close a temporary file, path=%s, errno=%d\n",
+                    tmp_path, errno);
 
-       return 0;
+       ret_val = 0;
+
+remove_tmp_path:
+       if (-1 == remove(tmp_path))
+               LOGE("Cannot remove a temporary file, path=%s, errno=%d\n",
+                    tmp_path, errno);
+out:
+       return ret_val;
 }
 
 // return 0 for normal case
index f8101acd5814a9cea2fa3943a824e98d9a40b3d4..a075629a370b9ef79cc44e2c1879342ff77b26e6 100644 (file)
@@ -190,9 +190,9 @@ void application_exit()
        snprintf(buf, sizeof(buf), "/proc/%d/cmdline", gpid);
        f = fopen(buf, "r");
        if (f != NULL) {
-               fscanf(f, "%" TOSTRING(MAX_PATH_LENGTH) "s", buf);
+               int n = fscanf(f, "%" TOSTRING(MAX_PATH_LENGTH) "s", buf);
                fclose(f);
-               if (strlen(buf) == strlen(manager_name) &&
+               if (n == 1 && strlen(buf) == strlen(manager_name) &&
                    strncmp(buf, manager_name, sizeof(manager_name)) == 0) {
                        PRINTMSG("App termination: EXIT(0)");
                        exit(0);
index cd98e7130454e5fb003bd49bbddc9068c501996a..685412ad73a34657473112a9181a451ee6ca31b4 100644 (file)
@@ -464,7 +464,10 @@ void print_log_ui_viewer_info_list(Eina_Bool rendering)
                if (uihv_data_send_to_socket(path))
                        PRINTERR("Cannot send uihv_data");
        }
-       remove(path);
+
+       if (-1 == remove(path))
+               PRINTERR("Cannot remove a temporary file, path=%s, errno=%d",
+                        path, errno);
 
        set_hierarchy_status(HIERARCHY_NOT_RUNNING);
 }