Repository: brooklyn-client
Updated Branches:
  refs/heads/master bf696e55b -> 285013a19


Close config file object (deferred close)


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-client/commit/daf8fea0
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-client/tree/daf8fea0
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-client/diff/daf8fea0

Branch: refs/heads/master
Commit: daf8fea098c4ff2e9ea2468ae7f9cf73c69a40dc
Parents: bf696e5
Author: Lyuben Blagoev <lblag...@gmail.com>
Authored: Thu Mar 17 09:33:28 2016 +0200
Committer: Lyuben Blagoev <lblag...@gmail.com>
Committed: Thu Mar 17 09:33:28 2016 +0200

----------------------------------------------------------------------
 io/config.go | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-client/blob/daf8fea0/io/config.go
----------------------------------------------------------------------
diff --git a/io/config.go b/io/config.go
index 4ba80ab..ea9ca01 100644
--- a/io/config.go
+++ b/io/config.go
@@ -20,9 +20,10 @@ package io
 
 import (
        "encoding/json"
-       "github.com/apache/brooklyn-client/error_handler"
        "os"
        "path/filepath"
+
+       "github.com/apache/brooklyn-client/error_handler"
 )
 
 type Config struct {
@@ -48,12 +49,12 @@ func GetConfig() (config *Config) {
 }
 
 func (config *Config) Write() {
-
        // Create file as read/write by user (but does not change perms of 
existing file)
        fileToWrite, err := os.OpenFile(config.FilePath, 
os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
        if err != nil {
                error_handler.ErrorExit(err)
        }
+       defer fileToWrite.Close()
 
        enc := json.NewEncoder(fileToWrite)
        enc.Encode(config.Map)
@@ -64,6 +65,8 @@ func (config *Config) Read() {
        if err != nil {
                error_handler.ErrorExit(err)
        }
+       defer fileToRead.Close()
+
        dec := json.NewDecoder(fileToRead)
        dec.Decode(&config.Map)
 }

Reply via email to