From adbae79565220ab8d8416d946e8543f9601f2ccb Mon Sep 17 00:00:00 2001 From: Vimal K Date: Wed, 4 Sep 2019 23:38:14 +0100 Subject: [PATCH] wal : wal.Verify defer close the opened WAL files wal.Verify() : The opened WAL files are not closed in error cases. Fixed by adding a defer. --- wal/wal.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/wal/wal.go b/wal/wal.go index 5f6f21e3a..e177c8e00 100644 --- a/wal/wal.go +++ b/wal/wal.go @@ -554,6 +554,11 @@ func Verify(lg *zap.Logger, walDir string, snap walpb.Snapshot) error { if err != nil { return err } + defer func() { + if closer != nil { + closer() + } + }() // create a new decoder from the readers on the WAL files decoder := newDecoder(rs...) @@ -591,10 +596,6 @@ func Verify(lg *zap.Logger, walDir string, snap walpb.Snapshot) error { } } - if closer != nil { - closer() - } - // We do not have to read out all the WAL entries // as the decoder is opened in read mode. if err != io.EOF && err != io.ErrUnexpectedEOF {