]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
proc_cpuview: unlock mutex in all error paths
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 31 Aug 2021 13:45:21 +0000 (15:45 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 31 Aug 2021 13:46:20 +0000 (15:46 +0200)
Fixes: #472
Reported-by: ycaibb@gmail.com
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/proc_cpuview.c

index aaa3f531d4162cbd646859c8f0b10cf35c5be24c..cbb03757379d14d198d034b046e0bd977603082c 100644 (file)
@@ -613,7 +613,7 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
 
        diff = zalloc(sizeof(struct cpuacct_usage) * nprocs);
        if (!diff)
-               return 0;
+               goto out_pthread_mutex_unlock;
 
        /*
         * If the new values are LOWER than values stored in memory, it means
@@ -657,7 +657,6 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
                uint64_t max_diff_idle = 0;
                uint64_t max_diff_idle_index = 0;
                double exact_cpus;
-
                /* threshold = maximum usage per cpu, including idle */
                threshold = total_sum / cpu_cnt * max_cpus;
 
@@ -767,8 +766,11 @@ int cpuview_proc_stat(const char *cg, const char *cpuset,
                total_len = 0;
                goto out_pthread_mutex_unlock;
        }
-       if (l >= buf_size)
-               return log_error(0, "Write to cache was truncated");
+       if (l >= buf_size) {
+               lxcfs_error("Write to cache was truncated");
+               total_len = 0;
+               goto out_pthread_mutex_unlock;
+       }
 
        buf += l;
        buf_size -= l;