Skip to content

Commit 95028b1

Browse files
authored
fix: duckdb varchar leak (#3631)
The caller is responsible for free-ing the memory with `duckdb_free`. Signed-off-by: Alexander Droste <[email protected]>
1 parent 9b52817 commit 95028b1

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

vortex-duckdb/src/convert/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn try_from_table_filter(value: &TableFilter, col: &str) -> VortexResult<Opt
5555
fn like_pattern_str(value: &Expression) -> VortexResult<Option<String>> {
5656
match value.as_class().vortex_expect("unknown class") {
5757
ExpressionClass::BoundConstant(constant) => {
58-
Ok(Some(format!("%{}%", constant.value.as_string().to_str()?)))
58+
Ok(Some(format!("%{}%", constant.value.as_string())))
5959
}
6060
_ => Ok(None),
6161
}

vortex-duckdb/src/convert/scalar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl TryFrom<Value> for Scalar {
260260
Ok(Scalar::utf8(str, Nullable))
261261
}
262262
DUCKDB_TYPE::DUCKDB_TYPE_BLOB => Ok(Scalar::binary(
263-
ByteBuffer::copy_from(value.as_string().to_str()?),
263+
ByteBuffer::copy_from(value.as_string()),
264264
Nullable,
265265
)),
266266
DUCKDB_TYPE::DUCKDB_TYPE_TIMESTAMP_S => Ok(Scalar::extension(

vortex-duckdb/src/duckdb/value.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,14 @@ impl Value {
7171
unsafe { Self::own(cpp::duckdb_create_date(cpp::duckdb_date { days })) }
7272
}
7373

74-
pub fn as_string(&self) -> &CStr {
75-
unsafe { CStr::from_ptr(cpp::duckdb_get_varchar(self.as_ptr())) }
74+
pub fn as_string(&self) -> String {
75+
unsafe {
76+
let ptr = cpp::duckdb_get_varchar(self.as_ptr());
77+
let cstr = CStr::from_ptr(ptr);
78+
let result = cstr.to_string_lossy().into_owned();
79+
cpp::duckdb_free(ptr.cast());
80+
result
81+
}
7682
}
7783

7884
pub fn as_u8(&self) -> u8 {

vortex-duckdb/src/scan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl TableFunction for VortexTableFunction {
170170
.get_parameter(0)
171171
.ok_or_else(|| vortex_err!("Missing file glob parameter"))?;
172172

173-
let paths = match glob::glob(file_glob_string.as_string().to_str()?) {
173+
let paths = match glob::glob(&file_glob_string.as_string()) {
174174
Ok(paths) => paths,
175175
Err(e) => vortex_bail!("Failed to glob files: {}", e),
176176
};

0 commit comments

Comments
 (0)