fix LevelDB CGO panic (#285)

This commit is contained in:
siddontang 2017-03-18 14:17:37 +08:00 committed by GitHub
parent 6ad692d5e1
commit 5929802e2e
2 changed files with 7 additions and 9 deletions

View File

@ -74,6 +74,8 @@ func NewReplication(cfg *config.Config) (*Replication, error) {
return nil, err
}
log.Infof("staring replication with commit ID %d", r.commitID)
r.wg.Add(1)
go r.run()
@ -88,6 +90,8 @@ func (r *Replication) Close() error {
r.m.Lock()
defer r.m.Unlock()
log.Infof("closing replication with commit ID %d", r.commitID)
if r.s != nil {
r.s.Close()
r.s = nil

View File

@ -16,15 +16,12 @@ import (
type WriteBatch struct {
db *DB
wbatch *C.leveldb_writebatch_t
gbatch *leveldb.Batch
}
func newWriteBatch(db *DB) *WriteBatch {
w := new(WriteBatch)
w.db = db
w.wbatch = C.leveldb_writebatch_create()
w.gbatch = new(leveldb.Batch)
return w
}
@ -34,8 +31,6 @@ func (w *WriteBatch) Close() {
C.leveldb_writebatch_destroy(w.wbatch)
w.wbatch = nil
}
w.gbatch = nil
}
func (w *WriteBatch) Put(key, value []byte) {
@ -97,9 +92,8 @@ func leveldb_writebatch_iterate_delete(p unsafe.Pointer, k *C.char, klen C.size_
}
func (w *WriteBatch) Data() []byte {
w.gbatch.Reset()
gbatch := leveldb.Batch{}
C.leveldb_writebatch_iterate_ext(w.wbatch,
unsafe.Pointer(w.gbatch))
b := w.gbatch.Dump()
return b
unsafe.Pointer(&gbatch))
return gbatch.Dump()
}