Skip to content

Commit 781d295

Browse files
committed
Resolves #109
1 parent db896d4 commit 781d295

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/lib.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,9 @@ impl Aligner<Built> {
906906
/// Remainds valid as long as the aligner is valid
907907
pub fn get_seq<'aln>(&'aln self, i: usize) -> Option<&'aln mm_idx_seq_t> {
908908
unsafe {
909-
let idx = Arc::as_ptr(self.idx.as_ref().unwrap());
910-
let idx: *const mm_idx_t = *idx;
909+
// let idx = Arc::as_ptr(self.idx.as_ref().unwrap());
910+
// let idx: *const mm_idx_t = *idx;
911+
let idx: *const mm_idx_t = &(***self.idx.as_ref().unwrap());
911912
// todo, should this be > or >=
912913
if i > self.n_seq() as usize {
913914
return None;
@@ -1110,7 +1111,8 @@ impl Aligner<Built> {
11101111
};
11111112

11121113
let (cs_str, md_str) = if cs || md {
1113-
let idx: *const mm_idx_t = *Arc::as_ptr(self.idx.as_ref().unwrap());
1114+
// let idx: *const mm_idx_t = *Arc::as_ptr(self.idx.as_ref().unwrap());
1115+
let idx: *const mm_idx_t = &(***self.idx.as_ref().unwrap());
11141116

11151117
let cs_str = if cs {
11161118
let mut cs_string: *mut libc::c_char = std::ptr::null_mut();
@@ -2243,4 +2245,18 @@ mod tests {
22432245
MM_F_CIGAR as i64
22442246
);
22452247
}
2248+
2249+
#[test]
2250+
fn build_aligner_memory_leak() {
2251+
for _ in 0..100000 {
2252+
let aligner = Aligner::builder().map_ont();
2253+
let aligner = aligner
2254+
.with_index_threads(1)
2255+
.with_cigar()
2256+
.with_sam_out()
2257+
.with_sam_hit_only()
2258+
.with_seq_and_id(b"ACGGTAGAGAGGAAGAAGAAGGAATAGCGGACTTGTGTATTTTATCGTCATTCGTGGTTATCATATAGTTTATTGATTTGAAGACTACGTAAGTAATTTGAGGACTGATTAAAATTTTCTTTTTTAGCTTAGAGTCAATTAAAGAGGGCAAAATTTTCTCAAAAGACCATGGTGCATATGACGATAGCTTTAGTAGTATGGATTGGGCTCTTCTTTCATGGATGTTATTCAGAAGGAGTGATATATCGAGGTGTTTGAAACACCAGCGACACCAGAAGGCTGTGGATGTTAAATCGTAGAACCTATAGACGAGTTCTAAAATATACTTTGGGGTTTTCAGCGATGCAAAA", b"ref")
2259+
.unwrap();
2260+
}
2261+
}
22462262
}

0 commit comments

Comments
 (0)