Fix Coverity reported bugs 72/280272/1
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 26 Aug 2022 04:48:12 +0000 (13:48 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Fri, 26 Aug 2022 04:54:30 +0000 (13:54 +0900)
Change-Id: I639b29f936bf3b9bdf5bab7da71008336a4b7fd6
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/resource-optimizer/cpu/cpu-boosting.c
src/resourced/init.c

index b4d4ae5..bde8f96 100644 (file)
@@ -98,6 +98,9 @@ static int cpu_boosting_get_tids(pid_t pid, resource_pid_t *resource_pid)
                                tid_list = (int *)realloc(tid_list, alloc_count * sizeof(pid_t));
                                if (tid_list == NULL) {
                                        _E("[CPU-BOOSTING] Failed to allocate memory");
+                                       closedir(dir);
+                                       resource_pid->tid = NULL;
+                                       resource_pid->tid_count = 0;
                                        return RESOURCED_ERROR_OUT_OF_MEMORY;
                                }
                        }
@@ -331,11 +334,10 @@ static int cpu_boosting_enqueue_by_socket(int sock, struct cpu_boosting_input **
        /* Check body size */
        if (input->client_input.body_len > 0 &&
            input->client_input.pid.tid_count > 0) {
-               int *tid_list;
+               pid_t *tid_list;
                int body_len = input->client_input.body_len;
-               int tid_count = input->client_input.pid.tid_count;
 
-               tid_list = (int *)calloc(tid_count, sizeof(int));
+               tid_list = (pid_t *)calloc(1, body_len);
                if (tid_list == NULL) {
                        _E("[CPU-BOOSTING] Failed to allocate memory");
                        ret = RESOURCED_ERROR_OUT_OF_MEMORY;
index 4e42537..8d2fc82 100644 (file)
@@ -117,14 +117,16 @@ static void sig_term_handler(int sig, siginfo_t *siginfo, void *context)
        char appname[PROC_NAME_MAX];
        pid_t sender_pid = siginfo->si_pid;
 
-       proc_get_cmdline(sender_pid, appname, sizeof(appname));
-       _D("signal = %d sender pid = %d (%s)", sig, sender_pid, appname);
+       if (proc_get_cmdline(sender_pid, appname, sizeof(appname)) < 0)
+               _D("signal = %d sender pid = %d", sig, sender_pid);
+       else
+               _D("signal = %d sender pid = %d (%s)", sig, sender_pid, appname);
        resourced_quit_mainloop();
 }
 
 static void add_signal_handler(void)
 {
-       struct sigaction sig_act;
+       struct sigaction sig_act = {0,};
 
        sig_act.sa_sigaction = sig_term_handler;
        sig_act.sa_flags = 0;