[lxc-devel] [PATCH 1/3] lxc-start: fix the container leak when daemonize

Serge Hallyn serge.hallyn at ubuntu.com
Thu Jan 23 17:17:34 UTC 2014


Quoting Qiang Huang (h.huangqiang at huawei.com):
> I already reasoned in the added comment, we need this because if not,
> lxc_container won't be freed when daemon exits, and PID file won't
> be unlinked either.

I see, but

> What about this:
> 
> From 80f3862f9c4dbc8a05e79e50c50e79e30ffebc25 Mon Sep 17 00:00:00 2001
> From: Qiang Huang <h.huangqiang at huawei.com>
> Date: Thu, 23 Jan 2014 14:25:31 +0800
> Subject: [PATCH] daemon: add lxc_container_put to free container when daemon exits
> 
> PID file in lxc_container is unlinked when lxc_container_free,
> if we leak the container, the PID file also won't be removed
> after container down.
> 
> Signed-off-by: Qiang Huang <h.huangqiang at huawei.com>

I was about to ack this, but then it occurred to me that
this seems to show that the pidfile free shouldn't be done
through lxc_container_free().  The pidfile always gets
written right before the reboot: label, and should simply be
explicitly removed in the place where you are adding a
lxc_container_put().  That way it is symmetric;  by having
it in lxc_container_free(), it is not.

> ---
>  src/lxc/lxccontainer.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index 28de455..d76e386 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -669,9 +669,14 @@ reboot:
>  		goto reboot;
>  	}
> 
> -	if (daemonize)
> +	if (daemonize) {
> +		/* When daemon forked, he inherited father's
> +		 * lxc_container, so here need a put to free
> +		 * lxc_container.
> +		 */
> +		lxc_container_put(c);
>  		exit (ret == 0 ? true : false);
> -	else
> +	} else
>  		return (ret == 0 ? true : false);
>  }
> 
> -- 
> 1.8.3
> 
> > 
> >>  		exit (ret == 0 ? true : false);
> >>  	} else {
> >> -- 
> >> 1.8.3
> >>
> >>
> > 
> > .
> > 
> 
> 


More information about the lxc-devel mailing list