Skip to content

Commit

Permalink
fix(sqlite): do not ignore API misuse errors from sqlite3_finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt authored and mehcode committed Apr 9, 2021
1 parent f488f53 commit 5cf1af2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sqlx-core/src/sqlite/statement/virtual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::HashMap;
use bytes::{Buf, Bytes};
use libsqlite3_sys::{
sqlite3, sqlite3_clear_bindings, sqlite3_finalize, sqlite3_prepare_v3, sqlite3_reset,
sqlite3_stmt, SQLITE_OK, SQLITE_PREPARE_PERSISTENT,
sqlite3_stmt, SQLITE_MISUSE, SQLITE_OK, SQLITE_PREPARE_PERSISTENT,
};
use smallvec::SmallVec;
use std::i32;
Expand Down Expand Up @@ -201,7 +201,16 @@ impl Drop for VirtualStatement {

unsafe {
// https://sqlite.org/c3ref/finalize.html
let _ = sqlite3_finalize(handle.0.as_ptr());
let status = sqlite3_finalize(handle.0.as_ptr());
if status == SQLITE_MISUSE {
// Panic in case of detected misuse of SQLite API.
//
// sqlite3_finalize returns it at least in the
// case of detected double free, i.e. calling
// sqlite3_finalize on already finalized
// statement.
panic!("Detected sqlite3_finalize misuse.");
}
}
}
}
Expand Down

0 comments on commit 5cf1af2

Please sign in to comment.