From dcb3bca32ca62ed8ed5360f7d3cef5775910b5ae Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Mon, 19 Jan 2015 16:21:21 +0300 Subject: [PATCH] namespaces: destroy cgroups only on error paths Signed-off-by: Andrey Vagin --- namespaces/exec.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/namespaces/exec.go b/namespaces/exec.go index 0fd31be03..a4e1d383e 100644 --- a/namespaces/exec.go +++ b/namespaces/exec.go @@ -19,9 +19,7 @@ import ( // Move this to libcontainer package. // Exec performs setup outside of a namespace so that a container can be // executed. Exec is a high level function for working with container namespaces. -func Exec(args []string, env []string, console string, command *exec.Cmd, container *configs.Config, cgroupManager cgroups.Manager, state *configs.State) error { - var err error - +func Exec(args []string, env []string, console string, command *exec.Cmd, container *configs.Config, cgroupManager cgroups.Manager, state *configs.State) (err error) { // create a pipe so that we can syncronize with the namespaced process and // pass the state and configuration to the child process parent, child, err := newInitPipe() @@ -73,7 +71,11 @@ func Exec(args []string, env []string, console string, command *exec.Cmd, contai if err != nil { return terminate(err) } - defer cgroupManager.Destroy() + defer func() { + if err != nil { + cgroupManager.Destroy() + } + }() var networkState network.NetworkState if err := InitializeNetworking(container, command.Process.Pid, &networkState); err != nil {