Skip to content

DuckDB bindings are unsafe #3904

@gatesn

Description

@gatesn

Specifically, impl Clone for Vector can result in a dangling pointer in the "borrowed" version.

A better way to implement bindings might be:

/// An owned DuckDB vector
struct Vector {
   ptr: *mut duckdb_vector
}

/// A borrowed DuckDB vector
struct VectorRef<'a> {
  ptr: *const duckdb_vector,
  _phantom: PhantomData<&'a ()>,
} 

impl Vector {
   fn as_ref(&self) -> VectorRef<'_> {
      ...
   }
}

impl Drop for Vector {
   fn drop(self) {
     duckdb_free(self.ptr)
   }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    ext/duckdbRelates to the DuckDB integration

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions