[CRIU] [PATCH 2/5] rlimit: Allocate and free appropriate Core entry

Andrew Vagin avagin at parallels.com
Thu Mar 13 00:22:29 PDT 2014


On Wed, Mar 12, 2014 at 10:48:04PM +0400, Cyrill Gorcunov wrote:
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  pstree.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 

> diff --git a/pstree.c b/pstree.c
> index fc0f707df83a..b390aa2145fc 100644
> --- a/pstree.c
> +++ b/pstree.c
> @@ -18,6 +18,8 @@ struct pstree_item *root_item;
>  
>  void core_entry_free(CoreEntry *core)
>  {
> +	size_t i;
> +
>  	if (core) {
>  		arch_free_thread_info(core);
>  		if (core->thread_core)
> @@ -25,6 +27,12 @@ void core_entry_free(CoreEntry *core)
>  		xfree(core->thread_core);
>  		xfree(core->tc);
>  		xfree(core->ids);
> +		if (core->task_rlimits) {
> +			for (i = 0; i < core->task_rlimits->n_rlimits; i++)
> +				xfree(core->task_rlimits->rlimits[i]);
> +			xfree(core->task_rlimits->rlimits);
> +		}
> +		xfree(core->task_rlimits);
>  	}
>  }
>  
> @@ -41,6 +49,7 @@ CoreEntry *core_entry_alloc(int alloc_thread_info, int alloc_tc)
>  	core->mtype = CORE_ENTRY__MARCH;
>  
>  	if (alloc_thread_info) {
> +		TaskRlimitsEntry *task_rlimits;
>  		ThreadCoreEntry *thread_core;
>  		ThreadSasEntry *sas;
>  
> @@ -58,6 +67,28 @@ CoreEntry *core_entry_alloc(int alloc_thread_info, int alloc_tc)
>  			goto err;
>  		thread_sas_entry__init(sas);
>  		core->thread_core->sas = sas;
> +
> +		/*
> +		 * Thread group leader only.
> +		 */
> +		if (alloc_tc) {
> +			size_t i;
> +
> +			task_rlimits = xmalloc(sizeof(*task_rlimits));
> +			if (!task_rlimits)
> +				goto err;
> +			task_rlimits_entry__init(task_rlimits);
> +			task_rlimits->n_rlimits = RLIM_NLIMITS;
> +			task_rlimits->rlimits = xzalloc(pb_repeated_size(task_rlimits, rlimits));
> +			if (!task_rlimits->rlimits)
you forget to free task_rlimits, don't you?
> +				goto err;
> +			for (i = 0; i < task_rlimits->n_rlimits; i++) {
> +				task_rlimits->rlimits[i] = xmalloc(sizeof(*task_rlimits->rlimits[i]));
> +				if (!task_rlimits->rlimits[i])
> +					goto err;
> +			}
> +			core->task_rlimits = task_rlimits;
or this line must be above the allocation of task_rlimits->rlimits ...
> +		}
>  	}
>  
>  	if (alloc_tc) {

> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu



More information about the CRIU mailing list