Signed-off-by: Ismo Puustinen <ismo.puusti...@intel.com>

diff --git a/tests/libcg_ba.cpp b/tests/libcg_ba.cpp
index 322794b..f89a8a7 100644
--- a/tests/libcg_ba.cpp
+++ b/tests/libcg_ba.cpp
@@ -94,7 +94,7 @@ struct cgroup *cg::makenode(const string &name, const string 
&task_uid,
 
        cgroup_dbg("tuid %d, tgid %d, cuid %d, cgid %d\n", tuid, tgid, cuid, 
cgid);
 
-       cgroup_name = (char *) malloc(name.length());
+       cgroup_name = (char *) malloc(name.length() + 1);
        strncpy(cgroup_name, name.c_str(), name.length() + 1);
 
        ccg = cgroup_new_cgroup(cgroup_name);
@@ -112,6 +112,8 @@ struct cgroup *cg::makenode(const string &name, const 
string &task_uid,
                if (ret)
                        cout << "cg delete group failed " << errno << endl;
        }
+
+       free(cgroup_name);
        return ccg;
 }
 
@@ -121,9 +123,8 @@ struct cgroup *cg::makenodefromparent(const string &name)
        struct cgroup *ccg;
        int ret;
 
-       cgroup_name = (char *) malloc(name.length());
-       memset(cgroup_name, '\0', name.length());
-       strcpy(cgroup_name, name.c_str());
+       cgroup_name = (char *) malloc(name.length() + 1);
+       strncpy(cgroup_name, name.c_str(), name.length() + 1);
 
        ccg = cgroup_new_cgroup(cgroup_name);
        ret = cgroup_create_cgroup_from_parent(ccg, 1);
@@ -133,6 +134,8 @@ struct cgroup *cg::makenodefromparent(const string &name)
                if (ret)
                        cout << "cg delete group failed " << errno << endl;
        }
+
+       free(cgroup_name);
        return ccg;
 }
 
-- 
2.4.3


------------------------------------------------------------------------------
_______________________________________________
Libcg-devel mailing list
Libcg-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libcg-devel

Reply via email to