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

Pavel Emelyanov xemul at parallels.com
Wed Dec 16 09:46:01 PST 2015


On 12/16/2015 06:33 PM, Stanislav Kinsburskiy wrote:
> 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);

Original cg->path starts to leak with this patch.

> -				cg->path = m;
>  			}
>  		}
>  
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu
> .
> 



More information about the CRIU mailing list