Signed-off-by: Nikola Forró <nfo...@redhat.com>
---
 src/api.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/api.c b/src/api.c
index 734bcaf..6ddab01 100644
--- a/src/api.c
+++ b/src/api.c
@@ -1318,12 +1318,15 @@ static int __cgroup_attach_task_pid(char *path, pid_t 
tid)
        if (!tasks) {
                switch (errno) {
                case EPERM:
-                       return ECGROUPNOTOWNER;
+                       ret = ECGROUPNOTOWNER;
+                       break;
                case ENOENT:
-                       return ECGROUPNOTEXIST;
+                       ret = ECGROUPNOTEXIST;
+                       break;
                default:
-                       return ECGROUPNOTALLOWED;
+                       ret = ECGROUPNOTALLOWED;
                }
+               goto err;
        }
        ret = fprintf(tasks, "%d", tid);
        if (ret < 0) {
@@ -1342,7 +1345,8 @@ static int __cgroup_attach_task_pid(char *path, pid_t tid)
 err:
        cgroup_warn("Warning: cannot write tid %d to %s:%s\n",
                        tid, path, strerror(errno));
-       fclose(tasks);
+       if (tasks)
+               fclose(tasks);
        return ret;
 }
 
-- 
2.17.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to