mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-01-23 02:14:37 +00:00
cgroup: use xsprintf() in rewrite_cgsets()
v2: Added free of original cg->path. Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
696eeef6b4
commit
cdd2733b0a
1 changed files with 6 additions and 10 deletions
16
cgroup.c
16
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)) {
|
||||
|
||||
char *tmp = cg->path;
|
||||
|
||||
/* +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 = 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue