[CRIU] [PATCH 4/7] cgroup: use construct_string() in rewrite_cgsets()

Stanislav Kinsburskiy skinsbursky at virtuozzo.com
Wed Dec 16 07:33:22 PST 2015


Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
 cgroup.c |   12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/cgroup.c b/cgroup.c
index 4d603b7..343cd23 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -1315,16 +1315,10 @@ static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controller
 
 				/* +1 to get rid of leading /, again */
 				int off = strlen(from) + 1;
-
-				/* +1 for trailing NULL */
-				int newlen = strlen(to) + strlen(cg->path + off) + 1;
-				char *m = xmalloc(newlen * sizeof(char*));
-				if (!m)
+				cg->path = construct_string("%s%s", to,
+							    cg->path + off);
+				if (!cg->path)
 					return -1;
-
-				sprintf(m, "%s%s", to, cg->path + off);
-				free(cg->path);
-				cg->path = m;
 			}
 		}
 



More information about the CRIU mailing list