diff --git a/bucket_test.go b/bucket_test.go index bf1b48a8f..c75f71fff 100644 --- a/bucket_test.go +++ b/bucket_test.go @@ -423,6 +423,22 @@ func TestBucket_Delete_FreelistOverflow(t *testing.T) { }); err != nil { t.Fatal(err) } + + // Check more than an overflow's worth of pages are freed. + stats := db.Stats() + freePages := stats.FreePageN + stats.PendingPageN + if freePages <= 0xFFFF { + t.Fatalf("expected more than 0xFFFF free pages, got %v", freePages) + } + + // Free page count should be preserved on reopen. + if err := db.DB.Close(); err != nil { + t.Fatal(err) + } + db.MustReopen() + if reopenFreePages := db.Stats().FreePageN; freePages != reopenFreePages { + t.Fatalf("expected %d free pages, got %+v", freePages, db.Stats()) + } } // Ensure that accessing and updating nested buckets is ok across transactions. diff --git a/freelist.go b/freelist.go index 679fcbb8e..13ce51666 100644 --- a/freelist.go +++ b/freelist.go @@ -245,7 +245,7 @@ func (f *freelist) read(p *page) { if count == 0 { f.ids = nil } else { - ids := ((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[idx:count] + ids := ((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[idx:idx+count] f.ids = make([]pgid, len(ids)) copy(f.ids, ids)