From 5929802e2ea51f20e4ebb4076a8be2c899094e56 Mon Sep 17 00:00:00 2001 From: siddontang Date: Sat, 18 Mar 2017 14:17:37 +0800 Subject: [PATCH] fix LevelDB CGO panic (#285) --- rpl/rpl.go | 4 ++++ store/leveldb/batch.go | 12 +++--------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/rpl/rpl.go b/rpl/rpl.go index 29f8880..0ebf66d 100644 --- a/rpl/rpl.go +++ b/rpl/rpl.go @@ -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 diff --git a/store/leveldb/batch.go b/store/leveldb/batch.go index 9f5a076..cc1b024 100644 --- a/store/leveldb/batch.go +++ b/store/leveldb/batch.go @@ -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() }