You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix critical memory safety issue in Transaction API
PROBLEM:
Transaction was storing a raw *mut CBLDatabase pointer without ensuring
the underlying Database remains alive. This could lead to use-after-free
if the Database was dropped before the Transaction:
```rust
let transaction = {
let mut db = Database::open("test", None)?;
db.begin_transaction()? // db dropped here\!
};
transaction.commit()?; // 💥 Use-after-free\!
```
SOLUTION:
Transaction now owns a Database clone instead of a raw pointer:
- Transaction::new() calls db.clone() which uses reference counting
- Database::clone() calls retain() to increment CBLDatabase ref count
- When Transaction is dropped, Database is automatically released
- CBLDatabase stays alive for the entire Transaction lifetime
CHANGES:
- Transaction.db_ref: *mut CBLDatabase → Transaction.db: Database
- Transaction::new() takes &Database instead of *mut CBLDatabase
- All Transaction methods use self.db.get_ref() instead of raw pointer
- Memory safety now guaranteed through Rust's ownership system
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
0 commit comments