From 8f6d6bc6c70ccb7cae1ea5344be60e38d809b94c Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 4 Jun 2013 14:35:32 -0700 Subject: [PATCH] Fix nil pointer on some situatuion Upstream-commit: 63e80384ea753c74046c2a4c3f64229c359f466f Component: engine --- components/engine/container.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/components/engine/container.go b/components/engine/container.go index ef449653c4..0b54419122 100644 --- a/components/engine/container.go +++ b/components/engine/container.go @@ -357,14 +357,15 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s } } else { go func() { - defer stdinCloser.Close() - - cStdout, err := container.StdoutPipe() - if err != nil { - utils.Debugf("Error stdout pipe") - return + if stdinCloser != nil { + defer stdinCloser.Close() + } + + if cStdout, err := container.StdoutPipe(); err != nil { + utils.Debugf("Error stdout pipe") + } else { + io.Copy(&utils.NopWriter{}, cStdout) } - io.Copy(&utils.NopWriter{}, cStdout) }() } if stderr != nil { @@ -394,14 +395,15 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s } } else { go func() { - defer stdinCloser.Close() - - cStderr, err := container.StdoutPipe() - if err != nil { - utils.Debugf("Error stdout pipe") - return + if stdinCloser != nil { + defer stdinCloser.Close() + } + + if cStderr, err := container.StdoutPipe(); err != nil { + utils.Debugf("Error stdout pipe") + } else { + io.Copy(&utils.NopWriter{}, cStderr) } - io.Copy(&utils.NopWriter{}, cStderr) }() }