[CRIU] [PATCH v3 3/6] cgroup: use xsprintf() in rewrite_cgsets()

Stanislav Kinsburskiy skinsbursky at virtuozzo.com
Thu Dec 17 04:29:14 PST 2015


v2:
Added free of original cg->path.

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

diff --git a/cgroup.c b/cgroup.c
index 4d603b7..27be045 100644
--- a/cgroup.c
+++ b/cgroup.c
@@ -1313,18 +1313,14 @@ static int rewrite_cgsets(CgroupEntry *cge, char **controllers, int n_controller
 					/* +1 to get rid of leading / */
 					strstartswith(cg->path + 1, from)) {
 
-				/* +1 to get rid of leading /, again */
-				int off = strlen(from) + 1;
+				char *tmp = cg->path;
 
-				/* +1 for trailing NULL */
-				int newlen = strlen(to) + strlen(cg->path + off) + 1;
-				char *m = xmalloc(newlen * sizeof(char*));
-				if (!m)
+				/* +1 to get rid of leading /, again */
+				cg->path = xsprintf("%s%s", to, cg->path +
+							strlen(from) + 1);
+				if (!cg->path)
 					return -1;
-
-				sprintf(m, "%s%s", to, cg->path + off);
-				free(cg->path);
-				cg->path = m;
+				free(tmp);
 			}
 		}
 



More information about the CRIU mailing list