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 18834a9191
commit 3232605524

View file

@ -117,6 +117,7 @@ func newPart(ph *partHeader, path string, size uint64, metaindexReader filestrea
p.indexFile = indexFile
p.metaindex = metaindex
p.ibCache = newIndexBlockCache()
if len(errors) > 0 {
// 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
}
p.ibCache = newIndexBlockCache()
return &p, nil
}