Java Bindings: prevent segfault from double delete

Give BackupableDB sole responsibility of the native
object to prevent RocksDB from also trying to delete
it.
main
Bob Potter 11 years ago
parent b2cf95fe38
commit 5fe176d8f6
  1. 4
      java/org/rocksdb/BackupableDB.java
  2. 12
      java/org/rocksdb/RocksDB.java

@ -31,6 +31,10 @@ public class BackupableDB extends RocksDB {
BackupableDB bdb = new BackupableDB(RocksDB.open(opt, db_path)); BackupableDB bdb = new BackupableDB(RocksDB.open(opt, db_path));
bdb.open(bdb.db_.nativeHandle_, bopt.nativeHandle_); 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; return bdb;
} }

@ -337,6 +337,18 @@ public class RocksDB extends RocksObject {
opt.filter_ = null; 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 // native methods
protected native void open( protected native void open(
long optionsHandle, long cacheSize, String path) throws RocksDBException; long optionsHandle, long cacheSize, String path) throws RocksDBException;

Loading…
Cancel
Save