From d3b8e21829bd671a1717fed8ab645ad2d447899a Mon Sep 17 00:00:00 2001
From: holyfei <yangfeiyu20092010@163.com>
Date: Wed, 19 Aug 2020 22:18:05 +0800
Subject: [PATCH 48/50] console: fix the file resource leak

reason:  newConsole will open a file, if error occurs in the
middle proccess, the file resource may leak, use defer close
to prevent it

Signed-off-by: yangfeiyu <yangfeiyu2@huawei.com>
---
 cli/console.go | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/cli/console.go b/cli/console.go
index c1555c9f..97dfee99 100644
--- a/cli/console.go
+++ b/cli/console.go
@@ -47,6 +47,12 @@ func newConsole() (*Console, error) {
 	if err != nil {
 		return nil, err
 	}
+	defer func() {
+		if err != nil {
+			master.Close()
+		}
+	}()
+	
 	if err := saneTerminal(master); err != nil {
 		return nil, err
 	}
-- 
2.14.3 (Apple Git-98)

