go/store/nbs: journal.go: Fix some nil dereference panics is rarely executed error handling code regarding a journal manifest in readOnly mode.

This commit is contained in:
Aaron Son
2023-11-28 17:03:10 -08:00
parent 3c9d6342d3
commit 59f3de6a4f

View File

@@ -528,7 +528,9 @@ func newJournalManifest(ctx context.Context, dir string) (m *journalManifest, er
var f *os.File
f, err = openIfExists(filepath.Join(dir, manifestFileName))
if err != nil {
_ = lock.Unlock()
if lock != nil {
_ = lock.Unlock()
}
return nil, err
} else if f == nil {
return m, nil
@@ -538,17 +540,23 @@ func newJournalManifest(ctx context.Context, dir string) (m *journalManifest, er
err = cerr // keep first error
}
if err != nil {
_ = lock.Unlock()
if lock != nil {
_ = lock.Unlock()
}
}
}()
var ok bool
ok, _, err = m.ParseIfExists(ctx, &Stats{}, nil)
if err != nil {
_ = lock.Unlock()
if lock != nil {
_ = lock.Unlock()
}
return nil, err
} else if !ok {
_ = lock.Unlock()
if lock != nil {
_ = lock.Unlock()
}
return nil, ErrUnreadableManifest
}
return