fix prevent violation
authorwoojin <woojin2.jung@samsung.com>
Sat, 20 Apr 2013 12:29:30 +0000 (21:29 +0900)
committerwoojin <woojin2.jung@samsung.com>
Sat, 20 Apr 2013 12:29:30 +0000 (21:29 +0900)
Change-Id: I79d60327b4a0b937baa175c79868a05f824173d4

daemon/da_debug.c
daemon/daemon.c
daemon/main.c
daemon/sys_stat.c
daemon/threads.c
daemon/utils.c
eventutil/eventutil.c

index f4b02ce..8592581 100644 (file)
@@ -42,16 +42,23 @@ void initialize_log()
     int fd;
 
     fd = open("/dev/null", O_RDONLY);
-    dup2(fd, 0);
+       if(fd >= 0)
+       {
+               dup2(fd, 0);
+               close(fd);
+       }
 
     fd = open(DEBUG_LOGFILE, O_WRONLY | O_CREAT | O_TRUNC, 0777);
     if(fd < 0) {
         fd = open("/dev/null", O_WRONLY);
-    }
+               if(fd < 0) 
+                       return;
+       }
     dup2(fd, 1);
     dup2(fd, 2);
 
     fprintf(stderr, "--- daemon starting (pid %d) ---\n", getpid());
+       close(fd);
 }
 #else
 void initialize_log()
index 42ea315..adff580 100644 (file)
@@ -723,7 +723,7 @@ static int controlSocketHandler()
        msg_t log;
 
        // host log format xxx|length|str
-       recvLen = recv(manager.host.control_socket, recvBuf, RECV_BUF_MAX, 0);
+       recvLen = recv(manager.host.control_socket, recvBuf, DA_MSG_MAX, 0);
 
        if (recvLen > 0)
        {
@@ -874,7 +874,7 @@ int daemonLoop()
                        else if(events[i].data.fd == manager.host.data_socket)
                        {
                                char recvBuf[32];
-                               recvLen = recv(manager.host.data_socket, recvBuf, RECV_BUF_MAX, MSG_DONTWAIT);
+                               recvLen = recv(manager.host.data_socket, recvBuf, 32, MSG_DONTWAIT);
                                if(recvLen == 0)
                                {       // close data socket
                                        epoll_ctl(efd, EPOLL_CTL_DEL, manager.host.data_socket, NULL);
index 3c14cd2..b6a996f 100644 (file)
@@ -214,9 +214,11 @@ static int singleton(void)
        {
                writeToPortfile(ERR_ALREADY_RUNNING);
                LOGE("another instance of daemon is already running");
+               close(fd);
                return -1;
        }
 
+       close(fd);
        return 0;
 }
 
index 1562957..d1b5249 100644 (file)
@@ -261,6 +261,7 @@ static int get_brightness_status()
                                        brightness_status = get_file_status(&brightnessfd, fullpath);
                                }
                        }
+                       closedir(dir_info);
                }
                else
                {
@@ -300,6 +301,7 @@ static int get_max_brightness()
                                        max_brightness = get_file_status(&maxbrightnessfd, fullpath);
                                }
                        }
+                       closedir(dir_info);
                }
                else
                {
@@ -1215,6 +1217,7 @@ static unsigned long get_system_total_memory()
        if((num = read(meminfo_fd, buf, BUFFER_MAX)) < 0)
        {
                LOGE("Failed to read from " PROCMEMINFO "\n");
+               close(meminfo_fd);
                return 0;
        }
        buf[num] = '\0';
index d16432b..11dbc74 100644 (file)
@@ -159,7 +159,7 @@ static void* recvThread(void* data)
                }
 #endif
 
-               // any message before MSG_PID message arrived did not be sent to host
+               // do not send any message to host until MSG_PID message arrives
                if(unlikely(pass == 0))
                {
                        while(manager.target[index].initial_log == 0)
@@ -193,7 +193,7 @@ int makeRecvThread(int index)
 
 static void* samplingThread(void* data)
 {
-       int err, signo, i;
+       int err, signo, i, res;
        int pidarray[MAX_TARGET_COUNT];
        int pidcount;
        sigset_t waitsigmask;
@@ -223,10 +223,11 @@ static void* samplingThread(void* data)
                                        pidarray[pidcount++] = manager.target[i].pid;
                        }
 
-                       log.length = get_resource_info(log.data, DA_MSG_MAX, pidarray, pidcount);
-                       if(log.length >= 0)
+                       res = get_resource_info(log.data, DA_MSG_MAX, pidarray, pidcount);
+                       if(res >= 0)
                        {
                                log.type = MSG_RESOURCE;
+                               log.length = res;
                                sendDataToHost(&log);
                        }
                }
@@ -237,8 +238,8 @@ static void* samplingThread(void* data)
                }
                else
                {
-                       // not happened
-                       LOGE("This should not be happend in sampling thread\n");
+                       // never happen
+                       LOGE("This should never happen in sampling thread\n");
                }
        }
 
index e7b822a..c14a444 100644 (file)
@@ -188,9 +188,11 @@ void set_appuser_groups(void)
                if(setgroups(sizeof(groups) / sizeof(groups[0]), groups) != 0)
                {
                        fprintf(stderr, "set groups failed errno: %d\n", errno);
+                       close(fd);
                        exit(1);
                }
        }
+       close(fd);
 }
 
 int get_smack_label(const char* execpath, char* buffer, int buflen)
index 8cefefd..53b42a1 100644 (file)
@@ -89,7 +89,7 @@ static int _file_read(FILE* fp, char *buffer, int size)
 static int get_input_id(char* inputname)
 {
        static int query_cmd_type = 0;  // 1 if /lib/udev/input_id, 2 if udevadm
-       FILE* cmd_fp;
+       FILE* cmd_fp = NULL;
        char buffer[BUF_SIZE];
        char command[MAX_FILENAME];
        int ret = -1;
@@ -108,7 +108,8 @@ static int get_input_id(char* inputname)
                {
                        query_cmd_type = 2;
                }
-               pclose(cmd_fp);
+               if(cmd_fp != NULL)
+                       pclose(cmd_fp);
        }
 
        // make command string
@@ -149,7 +150,8 @@ static int get_input_id(char* inputname)
                ret = INPUT_ID_TOUCH;
        }
 
-       pclose(cmd_fp);
+       if(cmd_fp != NULL)
+               pclose(cmd_fp);
        return ret;
 }
 
@@ -162,22 +164,24 @@ static void _get_fds(input_dev *dev, int input_id)
 
        dp = opendir("/sys/class/input");
 
-       while((d = readdir(dp)) != NULL)
+       if(dp != NULL)
        {
-               if(!strncmp(d->d_name, "event", 5))     // start with "event"
+               while((d = readdir(dp)) != NULL)
                {
-                       // event file
-                       if(input_id == get_input_id(d->d_name))
+                       if(!strncmp(d->d_name, "event", 5))     // start with "event"
                        {
-                               sprintf(dev[count].fileName, "/dev/input/%s", d->d_name);
-                               dev[count].fd = open(dev[count].fileName, O_RDWR);
-                               count++;
+                               // event file
+                               if(input_id == get_input_id(d->d_name))
+                               {
+                                       sprintf(dev[count].fileName, "/dev/input/%s", d->d_name);
+                                       dev[count].fd = open(dev[count].fileName, O_RDWR);
+                                       count++;
+                               }
                        }
                }
-       }
-
-       closedir(dp);
 
+               closedir(dp);
+       }
        dev[count].fd = ARRAY_END;      // end of input_dev array
 }