Browse code

Fix nil pointer on some situatuion

Guillaume J. Charmes authored on 2013/06/05 06:35:32
Showing 1 changed files
... ...
@@ -357,14 +357,15 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s
357 357
 		}
358 358
 	} else {
359 359
 		go func() {
360
-			defer stdinCloser.Close()
360
+			if stdinCloser != nil {
361
+				defer stdinCloser.Close()
362
+			}
361 363
 
362
-			cStdout, err := container.StdoutPipe()
363
-			if err != nil {
364
+			if cStdout, err := container.StdoutPipe(); err != nil {
364 365
 				utils.Debugf("Error stdout pipe")
365
-				return
366
+			} else {
367
+				io.Copy(&utils.NopWriter{}, cStdout)
366 368
 			}
367
-			io.Copy(&utils.NopWriter{}, cStdout)
368 369
 		}()
369 370
 	}
370 371
 	if stderr != nil {
... ...
@@ -394,14 +395,15 @@ func (container *Container) Attach(stdin io.ReadCloser, stdinCloser io.Closer, s
394 394
 		}
395 395
 	} else {
396 396
 		go func() {
397
-			defer stdinCloser.Close()
397
+			if stdinCloser != nil {
398
+				defer stdinCloser.Close()
399
+			}
398 400
 
399
-			cStderr, err := container.StdoutPipe()
400
-			if err != nil {
401
+			if cStderr, err := container.StdoutPipe(); err != nil {
401 402
 				utils.Debugf("Error stdout pipe")
402
-				return
403
+			} else {
404
+				io.Copy(&utils.NopWriter{}, cStderr)
403 405
 			}
404
-			io.Copy(&utils.NopWriter{}, cStderr)
405 406
 		}()
406 407
 	}
407 408