lib/storage: properly initialize part struct before trying to close it on error

This should prevent from nil pointer dereference bug at https://github.com/VictoriaMetrics/VictoriaMetrics/issues/468 .
This commit is contained in:
Aliaksandr Valialkin 2020-05-12 14:53:15 +03:00
parent cc825c483b
commit bd5f4e0344

View file

@ -117,6 +117,7 @@ func newPart(ph *partHeader, path string, size uint64, metaindexReader filestrea
p.indexFile = indexFile p.indexFile = indexFile
p.metaindex = metaindex p.metaindex = metaindex
p.ibCache = newIndexBlockCache()
if len(errors) > 0 { if len(errors) > 0 {
// Return only the first error, since it has no sense in returning all errors. // Return only the first error, since it has no sense in returning all errors.
@ -125,8 +126,6 @@ func newPart(ph *partHeader, path string, size uint64, metaindexReader filestrea
return nil, err return nil, err
} }
p.ibCache = newIndexBlockCache()
return &p, nil return &p, nil
} }