Skip to content

Commit d85ae5f

Browse files
authored
Merge pull request #111 from jguhlin/jg-branch-3
Fix memory leak
2 parents f144cf9 + c721f41 commit d85ae5f

File tree

8 files changed

+168
-120
lines changed

8 files changed

+168
-120
lines changed

CHANGELOG.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
### 0.1.23 minimap2 2.28
2+
+ Fixed memory leak when not dropping mm_idx_t properly. This is done by adding in syntactic sugar in minimap2-sys @jguhlin
3+
4+
### 0.1.22 minimap2 2.28
5+
#### Changes
6+
+ Fixed a memory segfault when re-using a thread local buffer. Not sure why it occurs, but this fix seems to solve it.
7+
8+
### 0.1.21 minimap2 2.28
9+
Contributors to this release: @mbhall88 @rob-p @Sam-Sims @charlesgregory @PB-DB
10+
#### Breaking Changes
11+
+ Map now returns Arc String's to reduce memory allocation for large and/or repetitive jobs
12+
+ map now takes an additional argument, query_name: Option<&[u8]>, possibly solves [#75](https://github.com/jguhlin/minimap2-rs/issues/75) (@rob-p @mbhall88 @jguhlin)
13+
+ Arc the Index, to prevent double-frees, solves [#71](https://github.com/jguhlin/minimap2-rs/issues/71)
14+
+ Map file now passes in query name, which should help with [#75](https://github.com/jguhlin/minimap2-rs/issues/75)
15+
+ Supplementary flag now better detected (@rob-p)
16+
+ FIX: Cigar string missing softclip operation (@Sam-Sims)
17+
18+
#### Migration Guide
19+
+ Make all setting changes before calling a with_index, with_seq's function
20+
+ Change all map calls to include a query name, or None if not needed
21+
22+
### Other Changes
23+
+ Add ergonomic functions n_seq and get_seq.
24+
+ Better docs on applying presets, solves [#84](https://github.com/jguhlin/minimap2-rs/issues/84)
25+
+ Better detection of target arch c_char's and ptr's, solves [#82](https://github.com/jguhlin/minimap2-rs/issues/82)
26+
+ Support for M1 Mac compilation and addition of github workflows to test it, solving [#81](https://github.com/jguhlin/minimap2-rs/issues/81)
27+
+ Rayon test, so some support, closes [#5](https://github.com/jguhlin/minimap2-rs/issues/5)
28+
+ Static str's and now static CStr's
29+
+ FIX: memory leak due to sequences allocated by minimap2 not being freed @charlesgregory
30+
+ Add Send + Sync to Aligner, along with unit test @PB-DB
31+
+ Experimental Android support (tested on aarch64 and x86_64), solves [#66](https://github.com/jguhlin/minimap2-rs/issues/66)
32+
+ Added flag and option documents
33+
+ Added with_gap_open penalty ergonomic function
34+
35+
### 0.1.20 minimap2 2.28
36+
+ Fix htslib errors. No update to -sys crate needed.
37+
38+
### 0.1.19 minimap2 2.28
39+
+ Fix memory leak by @charlesgregory
40+
41+
### 0.1.18 minimap2 2.28
42+
+ Update to minimap2 v2.28 @jguhlin
43+
+ Support for lrhqae preset @jguhlin
44+
45+
### 0.1.17 minimap2 2.27
46+
* Mark bam::Record objects as supplementary. #52 @PB-DB
47+
* Only use rust-htslib/curl when curl feature is enabled. #53 @PB-DB
48+
* Update to minimap2 v2.27 @jguhlin
49+
* Switch to needletail for reading fast files (features map-file) @jguhlin
50+
* Convert functions to take slices of vectors instead of refs to vecs `&[Vec<u8>]` instead of `&Vec<Vec<u8>>` @jguhlin
51+
* _breaking_ Curl is no longer a default option for htslib, please re-enable it as needed with cargo.toml features
52+
* _breaking_ Now using needletail for map-files, enabled by default. However, compression algorithms are disabled. Please enable with cargo.toml features
53+
* Experimental rayon support
54+
* aligner.with_cigar_clipping() to add soft clipping to the CIGAR vec (with_cigar() still adds to only the string, following the minimap2 outputs for PAF)
55+
* _breaking_ .with_threads(_) is now .with_index_threads(_) to make it more clear
56+
57+
### 0.1.16 minimap2 2.26
58+
* Much better cross compilation support thanks to @Adoni5
59+
60+
### 0.1.15 minimap2 2.26
61+
* Compilation on aarch64 thanks to @leiste375
62+
* README corrections thanks to @wdecoster
63+
* Better support for static builds / linking
64+
* Update fffx to a version that uses bytelines without tokio. Drastically reduces compile times and dependency tree.
65+
66+
### 0.1.14 minimap2 2.26
67+
* Memory leak fixed by @Adoni5
68+
* Updated deps
69+
70+
### 0.1.13 minimap2 2.26
71+
* Add with_seq to support indexing a single sequence (as per mappy: https://github.com/lh3/minimap2/blob/master/python/mappy.pyx#L115)
72+
* minimap2-rs: update rust-htslib deps
73+
* simdutf8 now optional dependency requiring map-file feature to be enabled
74+
* Support soft-clipping string in CIGAR. WARNING: Does not support hard clipping. Please open an issue if you need this.
75+
* Update minimap to 2.26
76+
* Not convinced SSE41/SSE2 are working properly. Recommend simde.
77+
78+
### 0.1.11
79+
* HTS lib: add support for optional quality scores by @eharr
80+
81+
### 0.1.10
82+
* HTS lib support by @eharr
83+
* HTS lib: Output sam/bam files by @eharr
84+
* More tests by @eharr
85+
* Display impl for Strand thanks to @ahcm
86+
* Update minimap2-sys to latest version by @jguhlin
87+
* -sys crate mm2fast added as additional backend by @jguhlin
88+
* zlib dep changes by @jguhlin (hopefully now it is more portable and robust)
89+
* -sys crate now supports SIMDe
90+
91+
## 0.1.9
92+
* Thanks for @Adoni5 for switching to builder pattern, and @eharr for adding additional fields to alignment.
93+
* Do not require libclang for normal compilation.
94+
## 0.1.8
95+
* Multithreading support (use less raw pointers, and treat more like rust Struct's)
96+
## 0.1.7
97+
* use libc instead of std:ffi::c_int as well
98+
## 0.1.6
99+
* Support slightly older versions of rustc by using libc:: rather than std::ffi for c_char (Thanks dwpeng!)
100+
* Use fffx module for fasta/q parsing

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "minimap2"
3-
version = "0.1.22+minimap2.2.28"
3+
version = "0.1.23+minimap2.2.28"
44
edition = "2021"
55
authors = ["Joseph Guhlin <[email protected]>"]
66
license = "MIT OR Apache-2.0"
@@ -31,14 +31,14 @@ libc = "0.2"
3131
needletail = { version = "0.6", optional = true, default-features = false}
3232

3333
# Dep for development
34-
minimap2-sys = { path = "./minimap2-sys", version = "0.1.20+minimap2.2.28" }
34+
minimap2-sys = { path = "./minimap2-sys" , version = "0.1.20+minimap2.2.28" }
3535
# minimap2-sys = "0.1.19"
36-
rust-htslib = { version = "0.48", default-features = false, optional = true }
36+
rust-htslib = { version = "0.49", default-features = false, optional = true }
3737

3838
[dev-dependencies]
3939
rayon = "1.10"
4040
crossbeam = "0.8.4"
41-
clap = { version = "4.5.21", features = ["derive"] }
41+
clap = { version = "4.5.23", features = ["derive"] }
4242
needletail = { version = "0.6", default-features = false}
4343

4444
# The end-user should decide this...
@@ -52,7 +52,7 @@ needletail = { version = "0.6", default-features = false}
5252

5353
[features]
5454
default = ["map-file"]
55-
map-file = ["needletail"] #, "simdutf8"]
55+
map-file = ["needletail"]
5656
htslib = ['rust-htslib']
5757
simde = ["minimap2-sys/simde"]
5858
zlib-ng = ["minimap2-sys/zlib-ng"]

README.md

Lines changed: 2 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Tested with rustc 1.82.0 and nightly. So probably a good idea to upgrade before
2020
## Minimap2 Version Table
2121
| minimap2-rs | minimap2 |
2222
|-------------|----------|
23+
| 0.1.23 | 2.28 |
2324
| 0.1.22 | 2.28 |
2425
| 0.1.21 | 2.28 |
2526
| 0.1.20 | 2.28 |
@@ -334,103 +335,7 @@ See [customization](#customization) for how to use these.
334335
| `MM_I_NO_NAME` | `4` | Do not store sequence names in the index. |
335336

336337
# Changelog
337-
### 0.1.22 minimap2 2.28
338-
#### Changes
339-
+ Fixed a memory segfault when re-using a thread local buffer. Not sure why it occurs, but this fix seems to solve it.
340-
341-
### 0.1.21 minimap2 2.28
342-
Contributors to this release: @mbhall88 @rob-p @Sam-Sims @charlesgregory @PB-DB
343-
#### Breaking Changes
344-
+ Map now returns Arc String's to reduce memory allocation for large and/or repetitive jobs
345-
+ map now takes an additional argument, query_name: Option<&[u8]>, possibly solves [#75](https://github.com/jguhlin/minimap2-rs/issues/75) (@rob-p @mbhall88 @jguhlin)
346-
+ Arc the Index, to prevent double-frees, solves [#71](https://github.com/jguhlin/minimap2-rs/issues/71)
347-
+ Map file now passes in query name, which should help with [#75](https://github.com/jguhlin/minimap2-rs/issues/75)
348-
+ Supplementary flag now better detected (@rob-p)
349-
+ FIX: Cigar string missing softclip operation (@Sam-Sims)
350-
351-
#### Migration Guide
352-
+ Make all setting changes before calling a with_index, with_seq's function
353-
+ Change all map calls to include a query name, or None if not needed
354-
355-
### Other Changes
356-
+ Add ergonomic functions n_seq and get_seq.
357-
+ Better docs on applying presets, solves [#84](https://github.com/jguhlin/minimap2-rs/issues/84)
358-
+ Better detection of target arch c_char's and ptr's, solves [#82](https://github.com/jguhlin/minimap2-rs/issues/82)
359-
+ Support for M1 Mac compilation and addition of github workflows to test it, solving [#81](https://github.com/jguhlin/minimap2-rs/issues/81)
360-
+ Rayon test, so some support, closes [#5](https://github.com/jguhlin/minimap2-rs/issues/5)
361-
+ Static str's and now static CStr's
362-
+ FIX: memory leak due to sequences allocated by minimap2 not being freed @charlesgregory
363-
+ Add Send + Sync to Aligner, along with unit test @PB-DB
364-
+ Experimental Android support (tested on aarch64 and x86_64), solves [#66](https://github.com/jguhlin/minimap2-rs/issues/66)
365-
+ Added flag and option documents
366-
+ Added with_gap_open penalty ergonomic function
367-
368-
### 0.1.20 minimap2 2.28
369-
+ Fix htslib errors. No update to -sys crate needed.
370-
371-
### 0.1.19 minimap2 2.28
372-
+ Fix memory leak by @charlesgregory
373-
374-
### 0.1.18 minimap2 2.28
375-
+ Update to minimap2 v2.28 @jguhlin
376-
+ Support for lrhqae preset @jguhlin
377-
378-
### 0.1.17 minimap2 2.27
379-
* Mark bam::Record objects as supplementary. #52 @PB-DB
380-
* Only use rust-htslib/curl when curl feature is enabled. #53 @PB-DB
381-
* Update to minimap2 v2.27 @jguhlin
382-
* Switch to needletail for reading fast files (features map-file) @jguhlin
383-
* Convert functions to take slices of vectors instead of refs to vecs `&[Vec<u8>]` instead of `&Vec<Vec<u8>>` @jguhlin
384-
* _breaking_ Curl is no longer a default option for htslib, please re-enable it as needed with cargo.toml features
385-
* _breaking_ Now using needletail for map-files, enabled by default. However, compression algorithms are disabled. Please enable with cargo.toml features
386-
* Experimental rayon support
387-
* aligner.with_cigar_clipping() to add soft clipping to the CIGAR vec (with_cigar() still adds to only the string, following the minimap2 outputs for PAF)
388-
* _breaking_ .with_threads(_) is now .with_index_threads(_) to make it more clear
389-
390-
### 0.1.16 minimap2 2.26
391-
* Much better cross compilation support thanks to @Adoni5
392-
393-
### 0.1.15 minimap2 2.26
394-
* Compilation on aarch64 thanks to @leiste375
395-
* README corrections thanks to @wdecoster
396-
* Better support for static builds / linking
397-
* Update fffx to a version that uses bytelines without tokio. Drastically reduces compile times and dependency tree.
398-
399-
### 0.1.14 minimap2 2.26
400-
* Memory leak fixed by @Adoni5
401-
* Updated deps
402-
403-
### 0.1.13 minimap2 2.26
404-
* Add with_seq to support indexing a single sequence (as per mappy: https://github.com/lh3/minimap2/blob/master/python/mappy.pyx#L115)
405-
* minimap2-rs: update rust-htslib deps
406-
* simdutf8 now optional dependency requiring map-file feature to be enabled
407-
* Support soft-clipping string in CIGAR. WARNING: Does not support hard clipping. Please open an issue if you need this.
408-
* Update minimap to 2.26
409-
* Not convinced SSE41/SSE2 are working properly. Recommend simde.
410-
411-
### 0.1.11
412-
* HTS lib: add support for optional quality scores by @eharr
413-
414-
### 0.1.10
415-
* HTS lib support by @eharr
416-
* HTS lib: Output sam/bam files by @eharr
417-
* More tests by @eharr
418-
* Display impl for Strand thanks to @ahcm
419-
* Update minimap2-sys to latest version by @jguhlin
420-
* -sys crate mm2fast added as additional backend by @jguhlin
421-
* zlib dep changes by @jguhlin (hopefully now it is more portable and robust)
422-
* -sys crate now supports SIMDe
423-
424-
## 0.1.9
425-
* Thanks for @Adoni5 for switching to builder pattern, and @eharr for adding additional fields to alignment.
426-
* Do not require libclang for normal compilation.
427-
## 0.1.8
428-
* Multithreading support (use less raw pointers, and treat more like rust Struct's)
429-
## 0.1.7
430-
* use libc instead of std:ffi::c_int as well
431-
## 0.1.6
432-
* Support slightly older versions of rustc by using libc:: rather than std::ffi for c_char (Thanks dwpeng!)
433-
* Use fffx module for fasta/q parsing
338+
See [CHANGELOG.md](CHANGELOG.md)
434339

435340
# Funding
436341
![Genomics Aotearoa](info/genomics-aotearoa.png)

minimap2-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "minimap2-sys"
3-
version = "0.1.20+minimap2.2.28"
3+
version = "0.1.21+minimap2.2.28"
44
edition = "2021"
55
links = "libminimap2"
66
authors = ["Joseph Guhlin <[email protected]>"]

minimap2-sys/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ mm2-fast and minimap2 have diverged. At this point mm2-fast is no longer support
1919
* Can we decouple from pthread? This would allow Windows and (possibly) WASM compilation.
2020

2121
## Changelog
22+
### 0.1.21 minimap2.2.28
23+
Syntactic sugar for mm_idx_t to support Drop, Deref, and DerefMut
24+
2225
### 0.1.20 minimap2.2.28
2326
* Move Drop impl to -sys crate
2427

minimap2-sys/src/lib.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
88
#[cfg(all(not(feature = "bindgen")))]
99
include!("bindings.rs");
1010

11+
use std::{mem::MaybeUninit, ops::{DerefMut, Deref}};
12+
1113
unsafe impl Send for mm_idx_t {}
1214
unsafe impl Send for mm_idx_reader_t {}
1315
unsafe impl Send for mm_mapopt_t {}
@@ -18,8 +20,35 @@ impl Drop for mm_idx_t {
1820
}
1921
}
2022

23+
pub struct MmIdx {
24+
pub idx: *mut mm_idx_t,
25+
}
26+
27+
impl From<*mut mm_idx_t> for MmIdx {
28+
fn from(idx: *mut mm_idx_t) -> Self {
29+
MmIdx { idx }
30+
}
31+
}
2132

22-
use std::mem::MaybeUninit;
33+
impl Drop for MmIdx {
34+
fn drop(&mut self) {
35+
unsafe { mm_idx_destroy(self.idx) };
36+
}
37+
}
38+
39+
impl Deref for MmIdx {
40+
type Target = mm_idx_t;
41+
42+
fn deref(&self) -> &Self::Target {
43+
unsafe { &*self.idx }
44+
}
45+
}
46+
47+
impl DerefMut for MmIdx {
48+
fn deref_mut(&mut self) -> &mut Self::Target {
49+
unsafe { &mut *self.idx }
50+
}
51+
}
2352

2453
impl Default for mm_mapopt_t {
2554
fn default() -> Self {

src/htslib.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,8 @@ pub struct SeqMetaData {
303303
pub is_alt: bool,
304304
}
305305

306-
#[derive(Debug)]
307306
pub struct MMIndex {
308-
pub inner: Arc<*mut mm_ffi::mm_idx_t>,
307+
pub inner: Arc<super::MmIdx>,
309308
}
310309

311310
impl MMIndex {
@@ -345,8 +344,7 @@ impl MMIndex {
345344
impl From<&Aligner<Built>> for MMIndex {
346345
fn from(aligner: &Aligner<Built>) -> Self {
347346
MMIndex {
348-
// inner: aligner.idx.unwrap(),
349-
inner: std::sync::Arc::clone(&aligner.idx.as_ref().unwrap()),
347+
inner: std::sync::Arc::clone(aligner.idx.as_ref().unwrap()),
350348
}
351349
}
352350
}

0 commit comments

Comments
 (0)