Skip to content

fix: fix leak in TableCollection::deepcopy #275

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/table_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ impl TableCollection {
Ok(tables)
}

fn new_uninit() -> Self {
Self::wrap()
}

pub(crate) fn into_raw(self) -> Result<*mut ll_bindings::tsk_table_collection_t, TskitError> {
let mut tables = self;
// rust won't let use move inner out b/c this type implements Drop.
Expand Down Expand Up @@ -1003,7 +1007,9 @@ impl TableCollection {

/// Return a "deep" copy of the tables.
pub fn deepcopy(&self) -> Result<TableCollection, TskitError> {
let mut copy = TableCollection::new(1.)?;
// The output is UNINITIALIZED tables,
// else we leak memory
let mut copy = Self::new_uninit();

let rv =
unsafe { ll_bindings::tsk_table_collection_copy(self.as_ptr(), copy.as_mut_ptr(), 0) };
Expand Down