Java Bindings: prevent segfault from double delete
Give BackupableDB sole responsibility of the native object to prevent RocksDB from also trying to delete it.
This commit is contained in:
parent
b2cf95fe38
commit
5fe176d8f6
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user