Skip to content

Commit 3feb5ba

Browse files
authored
fix: fix leak in TableCollection::deepcopy (#275)
1 parent 7ebed2b commit 3feb5ba

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/table_collection.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ impl TableCollection {
108108
Ok(tables)
109109
}
110110

111+
fn new_uninit() -> Self {
112+
Self::wrap()
113+
}
114+
111115
pub(crate) fn into_raw(self) -> Result<*mut ll_bindings::tsk_table_collection_t, TskitError> {
112116
let mut tables = self;
113117
// rust won't let use move inner out b/c this type implements Drop.
@@ -1003,7 +1007,9 @@ impl TableCollection {
10031007

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

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

0 commit comments

Comments
 (0)