From 790c3a3663d9b6be98825547d05557b90090821f Mon Sep 17 00:00:00 2001 From: "Justin Terry (VM)" Date: Wed, 1 Aug 2018 10:45:07 -0700 Subject: [PATCH] Remove extra allocation in NewTask Reorders the code so that it doesnt overwrite the previous allocation when creating a NewTask via ctr.exe Signed-off-by: Justin Terry (VM) --- cmd/ctr/commands/tasks/tasks_windows.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/ctr/commands/tasks/tasks_windows.go b/cmd/ctr/commands/tasks/tasks_windows.go index 32dd9e4dc..5235467fc 100644 --- a/cmd/ctr/commands/tasks/tasks_windows.go +++ b/cmd/ctr/commands/tasks/tasks_windows.go @@ -59,15 +59,16 @@ func HandleConsoleResize(ctx gocontext.Context, task resizer, con console.Consol // NewTask creates a new task func NewTask(ctx gocontext.Context, client *containerd.Client, container containerd.Container, _ string, tty, nullIO bool, ioOpts []cio.Opt, opts ...containerd.NewTaskOpts) (containerd.Task, error) { - ioCreator := cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...) + var ioCreator cio.Creator if tty { - ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...) - } - if nullIO { - if tty { + if nullIO { return nil, errors.New("tty and null-io cannot be used together") } + ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio, cio.WithTerminal}, ioOpts...)...) + } else if nullIO { ioCreator = cio.NullIO + } else { + ioCreator = cio.NewCreator(append([]cio.Opt{cio.WithStdio}, ioOpts...)...) } return container.NewTask(ctx, ioCreator) }