copy prop hash bucket contents to make them safe for long-term use
@@ -75,7 +75,16 @@ func (fs *Searcher) docPointersInvertedNoFrequency(prop string, b *lsmkv.Bucket,
return false, errors.Wrap(err, "get hash")
}
- hashes = append(hashes, currHash)
+ // currHash is only safe to access for the lifetime of the RowReader, once
+ // that has finished, a compaction could happen and remove the underlying
+ // memory that the slice points to. Since the hashes will be used to merge
+ // filters - which happens after the RowReader has completed - this can lead
+ // to segfault crashes. Now is the time to safely copy it, creating a new
+ // and immutable slice.
+ hashCopy := make([]byte, len(currHash))
+ copy(hashCopy, currHash)
+
+ hashes = append(hashes, hashCopy)
if limit > 0 && pointers.count >= uint64(limit) {
return false, nil
}
