Hi! I've run in an issue when dealing with a raw handle (I'm in a situation similar to #1477, where I have a raw handle and I need to query): rusqlite will remove all hooks when the non owning connection is dropped.
A small reproducer could be something on the lines of:
use rusqlite::{Connection, params};
fn main() {
let conn = Connection::open_in_memory().unwrap();
conn.commit_hook(Some(|| {
println!("committed!");
false
})).unwrap();
conn.execute("CREATE TABLE test(value)", params![]).unwrap(); // Prints "committed!"
{
let conn2 = unsafe { Connection::from_handle(conn.handle()) }.unwrap();
conn2.execute("INSERT INTO test(value) VALUES ('Test');", params![]).unwrap(); // Prints "committed!"
}
conn.execute("DROP TABLE test", params![]).unwrap(); // Doesn't print anything
}
Notice also that the original conn object is still keeping the boxed hook alive.
I do understand that conn2 needs to clean up hooks in case it registered them, otherwise it would create a use-after-free, but maybe it shouldn't clean them up when they weren't set?
If my reasoning above is sound, I can quickly post a PR to fix this behavior. Any feedback would be nice!
Hi! I've run in an issue when dealing with a raw handle (I'm in a situation similar to #1477, where I have a raw handle and I need to query): rusqlite will remove all hooks when the non owning connection is dropped.
A small reproducer could be something on the lines of:
Notice also that the original
connobject is still keeping the boxed hook alive.I do understand that
conn2needs to clean up hooks in case it registered them, otherwise it would create a use-after-free, but maybe it shouldn't clean them up when they weren't set?If my reasoning above is sound, I can quickly post a PR to fix this behavior. Any feedback would be nice!