From f894b80fc319da4d59374558650f6754356841bc Mon Sep 17 00:00:00 2001 From: link2xt Date: Fri, 9 Apr 2021 04:37:03 +0300 Subject: [PATCH] fix(sqlite): do not ignore API misuse errors from sqlite3_finalize --- sqlx-core/src/sqlite/statement/virtual.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/sqlx-core/src/sqlite/statement/virtual.rs b/sqlx-core/src/sqlite/statement/virtual.rs index 11072c1a02..9af20f8652 100644 --- a/sqlx-core/src/sqlite/statement/virtual.rs +++ b/sqlx-core/src/sqlite/statement/virtual.rs @@ -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; @@ -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."); + } } } }