From e3c21020805099d3673362b69882a53dbd258ce8 Mon Sep 17 00:00:00 2001 From: siddontang Date: Sat, 11 Oct 2014 10:31:34 +0800 Subject: [PATCH] closure defer not works as I think --- ledis/dump.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ledis/dump.go b/ledis/dump.go index 436e707..1f6d5e2 100644 --- a/ledis/dump.go +++ b/ledis/dump.go @@ -46,21 +46,22 @@ func (l *Ledis) Dump(w io.Writer) error { var commitID uint64 var snap *store.Snapshot - { - l.wLock.Lock() - defer l.wLock.Unlock() + l.wLock.Lock() - if l.r != nil { - if commitID, err = l.r.LastCommitID(); err != nil { - return err - } - } - - if snap, err = l.ldb.NewSnapshot(); err != nil { + if l.r != nil { + if commitID, err = l.r.LastCommitID(); err != nil { + l.wLock.Unlock() return err } } + if snap, err = l.ldb.NewSnapshot(); err != nil { + l.wLock.Unlock() + return err + } + + l.wLock.Unlock() + wb := bufio.NewWriterSize(w, 4096) h := &DumpHead{commitID}