Skip to content

Commit

Permalink
Fix some cgo memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jchiu0 committed Dec 7, 2016
1 parent 977a025 commit 4844c61
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions raftwal/wal.go
Expand Up @@ -89,6 +89,7 @@ func (w *Wal) Store(gid uint32, s raftpb.Snapshot, h raftpb.HardState, es []raft
start := w.entryKey(gid, t, i+1)
prefix := w.prefix(gid)
itr := w.wals.NewIterator()
defer itr.Close()

for itr.Seek(start); itr.ValidForPrefix(prefix); itr.Next() {
b.Delete(itr.Key().Data())
Expand Down Expand Up @@ -123,6 +124,7 @@ func (w *Wal) Entries(gid uint32, fromTerm, fromIndex uint64) (es []raftpb.Entry
start := w.entryKey(gid, fromTerm, fromIndex)
prefix := w.prefix(gid)
itr := w.wals.NewIterator()
defer itr.Close()

for itr.Seek(start); itr.ValidForPrefix(prefix); itr.Next() {
data := itr.Value().Data()
Expand Down
3 changes: 2 additions & 1 deletion rdb/db.go
Expand Up @@ -66,7 +66,8 @@ func (db *DB) Close() {
C.rdb_close(db.c)
}

// Get returns the data associated with the key from the database.
// Get returns the data associated with the key from the database. Remember
// to deallocate the returned Slice.
func (db *DB) Get(opts *ReadOptions, key []byte) (*Slice, error) {
var (
cErr *C.char
Expand Down
1 change: 1 addition & 0 deletions worker/predicate.go
Expand Up @@ -36,6 +36,7 @@ const (
// writeBatch performs a batch write of key value pairs to RocksDB.
func writeBatch(ctx context.Context, kv chan *task.KV, che chan error) {
wb := pstore.NewWriteBatch()
defer wb.Destroy()
batchSize := 0
batchWriteNum := 1
for i := range kv {
Expand Down

0 comments on commit 4844c61

Please sign in to comment.