Skip to content

Commit

Permalink
fix: implement Drop for faidx::Reader, destroying the fai handle (#391)
Browse files Browse the repository at this point in the history
* implement Drop for faidx::Reader, destroying the fai handle

* add testcase for creating and instantly dropping many faidx readers
  • Loading branch information
tedil authored May 16, 2023
1 parent 4ee2921 commit 0e6d6ac
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/faidx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ impl Reader {
}
}

impl Drop for Reader {
fn drop(&mut self) {
unsafe {
htslib::fai_destroy(self.inner);
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -238,4 +246,12 @@ mod tests {
let n = r.seq_name(1).unwrap();
assert_eq!(n, "chr2");
}

#[test]
fn open_many_readers() {
for _ in 0..500_000 {
let reader = open_reader();
drop(reader);
}
}
}

0 comments on commit 0e6d6ac

Please sign in to comment.