From 94f1ac599eb6c574da91486ca0d9e10e503e066b Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Fri, 28 Apr 2017 15:45:30 +0200 Subject: [PATCH] Fix closing of meta file if meta encoding failed --- block.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block.go b/block.go index d6aff93b5..8f5f25fe8 100644 --- a/block.go +++ b/block.go @@ -138,8 +138,10 @@ func writeMetaFile(dir string, meta *BlockMeta) error { enc := json.NewEncoder(f) enc.SetIndent("", "\t") - if err := enc.Encode(&blockMeta{Version: 1, BlockMeta: meta}); err != nil { - return err + var merr MultiError + if merr.Add(enc.Encode(&blockMeta{Version: 1, BlockMeta: meta})); merr.Err() != nil { + merr.Add(f.Close()) + return merr } if err := f.Close(); err != nil { return err