mirror of https://github.com/poanetwork/gecko.git
prevent potential memory leaks
This commit is contained in:
parent
2e13c33f23
commit
fc15e3cfe6
|
@ -17,6 +17,10 @@ import (
|
|||
"github.com/ava-labs/gecko/utils/hashing"
|
||||
)
|
||||
|
||||
const (
|
||||
minBatchSize = 32
|
||||
)
|
||||
|
||||
// Database encrypts all values that are provided
|
||||
type Database struct {
|
||||
lock sync.RWMutex
|
||||
|
@ -201,7 +205,7 @@ func (b *batch) Write() error {
|
|||
|
||||
// Reset resets the batch for reuse.
|
||||
func (b *batch) Reset() {
|
||||
b.writes = b.writes[:0]
|
||||
b.writes = make([]keyValue, 0, minBatchSize)
|
||||
b.Batch.Reset()
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,11 @@ import (
|
|||
"github.com/ava-labs/gecko/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultSize is the default initial size of the memory database
|
||||
const DefaultSize = 1 << 10
|
||||
DefaultSize = 1 << 10
|
||||
minBatchSize = 32
|
||||
)
|
||||
|
||||
// Database is an ephemeral key-value store that implements the Database
|
||||
// interface.
|
||||
|
@ -191,7 +194,7 @@ func (b *batch) Write() error {
|
|||
|
||||
// Reset implements the Batch interface
|
||||
func (b *batch) Reset() {
|
||||
b.writes = b.writes[:0]
|
||||
b.writes = make([]keyValue, 0, minBatchSize)
|
||||
b.size = 0
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ import (
|
|||
"github.com/ava-labs/gecko/utils/hashing"
|
||||
)
|
||||
|
||||
const (
|
||||
minBatchSize = 32
|
||||
)
|
||||
|
||||
// Database partitions a database into a sub-database by prefixing all keys with
|
||||
// a unique value.
|
||||
type Database struct {
|
||||
|
@ -199,7 +203,7 @@ func (b *batch) Write() error {
|
|||
|
||||
// Reset resets the batch for reuse.
|
||||
func (b *batch) Reset() {
|
||||
b.writes = b.writes[:0]
|
||||
b.writes = make([]keyValue, 0, minBatchSize)
|
||||
b.Batch.Reset()
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,10 @@ import (
|
|||
"github.com/ava-labs/gecko/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
minBatchSize = 32
|
||||
)
|
||||
|
||||
var (
|
||||
errClosed = fmt.Sprintf("rpc error: code = Unknown desc = %s", database.ErrClosed)
|
||||
errNotFound = fmt.Sprintf("rpc error: code = Unknown desc = %s", database.ErrNotFound)
|
||||
|
@ -180,7 +184,7 @@ func (b *batch) Write() error {
|
|||
}
|
||||
|
||||
func (b *batch) Reset() {
|
||||
b.writes = b.writes[:0]
|
||||
b.writes = make([]keyValue, 0, minBatchSize)
|
||||
b.size = 0
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue