Skip to content

Commit

Permalink
feat(ada_owned_string/Drop): add
Browse files Browse the repository at this point in the history
Clears the memory after the ada_owned_string goes out of scope. This ensures that ada_owned_string is cleared in user space.

BREAKING CHANGE: ada_owned_string was previously not freed upon going out of scope. Now it is.
  • Loading branch information
pratikpc committed May 20, 2024
1 parent e49e61d commit f9979bd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ impl AsRef<str> for ada_owned_string {
}
}

impl Drop for ada_owned_string {
fn drop(&mut self) {
// @note This is needed because ada_free_owned_string accepts by value
let copy = ada_owned_string {
data: self.data,
length: self.length,
};
unsafe {
ada_free_owned_string(copy);
};
}
}

#[repr(C)]
pub struct ada_url_components {
pub protocol_end: u32,
Expand Down

0 comments on commit f9979bd

Please sign in to comment.