]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
I tested a cgrlesengd daemon with huge load, which makes many 'su',
authorKen'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Thu, 7 May 2009 20:22:46 +0000 (01:52 +0530)
committerBalbir Singh <balbir@linux.vnet.ibm.com>
Thu, 7 May 2009 20:22:46 +0000 (01:52 +0530)
in long time. And the daemon was killed by an OOM killer. So the
daemon has memory leak. This patch fixes this problem.

The daemon allocates memory at cg_prepare_cgroup(), but it does not
free the memory. This patch adds necessary free() to cgroup_change_
cgroup_path by calling cgroup_free_controllers(). In addition, this
patch adds free()s for handling error and flushes the counters of the
allocations in cgroup_free_controllers().

Signed-off-by: Ken'ichi Ohmichi <oomichi@mxs.nes.nec.co.jp>
Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
src/api.c
src/wrapper.c

index baeb856a465b14844ed68a267807387e5622c68c..02022eba8e1c047efbe90f866836ffa1c1ef9ecc 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -1699,6 +1699,7 @@ unlock_error:
         * XX: Need to figure out how to cleanup? Cleanup just the stuff
         * we added, or the whole structure.
         */
+       cgroup_free_controllers(cgroup);
        cgroup = NULL;
        return error;
 }
@@ -1744,6 +1745,7 @@ static int cg_prepare_cgroup(struct cgroup *cgroup, pid_t pid,
                                                " failed\n",
                                                cg_mount_table[i].name);
                                        pthread_rwlock_unlock(&cg_mount_table_lock);
+                                       cgroup_free_controllers(cgroup);
                                        return ECGROUPNOTALLOWED;
                                }
                        }
@@ -1757,6 +1759,7 @@ static int cg_prepare_cgroup(struct cgroup *cgroup, pid_t pid,
                if (!cptr) {
                        cgroup_dbg("Adding controller '%s' failed\n",
                                controller);
+                       cgroup_free_controllers(cgroup);
                        return ECGROUPNOTALLOWED;
                }
        }
@@ -1975,11 +1978,10 @@ int cgroup_change_cgroup_path(char *dest, pid_t pid, char *controllers[])
                return ret;
        /* Add task to cgroup */
        ret = cgroup_attach_task_pid(&cgroup, pid);
-       if (ret) {
+       if (ret)
                cgroup_dbg("cgroup_attach_task_pid failed:%d\n", ret);
-               return ret;
-       }
-       return 0;
+       cgroup_free_controllers(&cgroup);
+       return ret;
 }
 
 /**
index 2f8fcf2fafb1c8d8e5f8745069cfdf989ac5fe99..1ee16659125f0ae5467031d10823339d30651175 100644 (file)
@@ -83,8 +83,10 @@ void cgroup_free_controllers(struct cgroup *cgroup)
        for (i = 0; i < cgroup->index; i++) {
                for (j = 0; j < cgroup->controller[i]->index; j++)
                        free(cgroup->controller[i]->values[j]);
+               cgroup->controller[i]->index = 0;
                free(cgroup->controller[i]);
        }
+       cgroup->index = 0;
 }
 
 void cgroup_free(struct cgroup **cgroup)