Prevent double allocations for VFilter args in vdbe

This commit is contained in:
PThorpe92 2025-04-17 13:11:21 -04:00
parent e17fd7edc4
commit d53c60e071
No known key found for this signature in database
GPG key ID: 66DB3FBACBDD05CC
2 changed files with 12 additions and 10 deletions

View file

@ -705,19 +705,16 @@ impl VirtualTable {
VTabOpaqueCursor::new(cursor)
}
#[tracing::instrument(skip(cursor))]
pub fn filter(
&self,
cursor: &VTabOpaqueCursor,
idx_num: i32,
idx_str: Option<String>,
arg_count: usize,
args: Vec<OwnedValue>,
args: Vec<limbo_ext::Value>,
) -> Result<bool> {
let mut filter_args = Vec::with_capacity(arg_count);
for i in 0..arg_count {
let ownedvalue_arg = args.get(i).unwrap();
filter_args.push(ownedvalue_arg.to_ffi());
}
tracing::trace!("xFilter");
let c_idx_str = idx_str
.map(|s| std::ffi::CString::new(s).unwrap())
.map(|cstr| cstr.into_raw())
@ -726,12 +723,12 @@ impl VirtualTable {
(self.implementation.filter)(
cursor.as_ptr(),
arg_count as i32,
filter_args.as_ptr(),
args.as_ptr(),
c_idx_str,
idx_num,
)
};
for arg in filter_args {
for arg in args {
unsafe {
arg.__free_internal_type();
}

View file

@ -979,9 +979,14 @@ pub fn op_vfilter(
let has_rows = {
let mut cursor = state.get_cursor(*cursor_id);
let cursor = cursor.as_virtual_mut();
let mut args = Vec::new();
let mut args = Vec::with_capacity(*arg_count);
for i in 0..*arg_count {
args.push(state.registers[args_reg + i].get_owned_value().clone());
args.push(
state.registers[args_reg + i]
.get_owned_value()
.clone()
.to_ffi(),
);
}
let idx_str = if let Some(idx_str) = idx_str {
Some(state.registers[*idx_str].get_owned_value().to_string())