提交 5fe176d8 编写于 作者: B Bob Potter

Java Bindings: prevent segfault from double delete

Give BackupableDB sole responsibility of the native
object to prevent RocksDB from also trying to delete
it.
上级 b2cf95fe
......@@ -31,6 +31,10 @@ public class BackupableDB extends RocksDB {
BackupableDB bdb = new BackupableDB(RocksDB.open(opt, db_path));
bdb.open(bdb.db_.nativeHandle_, bopt.nativeHandle_);
// Prevent the RocksDB object from attempting to delete
// the underly C++ DB object.
bdb.db_.disOwnNativeObject();
return bdb;
}
......
......@@ -337,6 +337,18 @@ public class RocksDB extends RocksObject {
opt.filter_ = null;
}
/**
* Revoke ownership of the native object.
*
* This will prevent the object from attempting to delete the underlying
* native object in its finalizer. This must be used when another object
* (e.g. BackupableDB) takes over ownership of the native object or both
* will attempt to delete the underlying object when garbage collected.
*/
protected void disOwnNativeObject() {
nativeHandle_ = 0;
}
// native methods
protected native void open(
long optionsHandle, long cacheSize, String path) throws RocksDBException;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册