8000 Fix index-reader ownership and error handling in set_index by MrTomRod · Pull Request #172 · jguhlin/minimap2-rs · GitHub
[go: up one dir, main page]

Skip to content

Fix index-reader ownership and error handling in set_index - #172

Open
MrTomRod wants to merge 1 commit into
jguhlin:mainfrom
MrTomRod:main
Open

MrTomRod wants to merge 1 commit into
jguhlin:mainfrom
MrTomRod:main

Conversation

@MrTomRod
Copy link
Copy Markdown

Description

This PR fixes an index-reader ownership issue and null pointer dereference in lib.rs:set_index:

  • Check mm_idx_reader_open return value before dereferencing; return a Rust error if null.
  • Wrap the raw reader pointer in an RAII guard (IdxReaderGuard) to ensure mm_idx_reader_close is called exactly once on all paths.
  • Store None for idx_reader in the returned Aligner rather than dereferencing and storing a copy of the freed reader struct.
  • Pass a null pointer for output to mm_idx_reader_open when None is provided instead of passing an empty string pointer.
  • Add focused regression tests covering reader ownership/round-trip behavior and error paths (empty file, unreadable file, truncated header).
  • Added assertion to the existing cloning test confirming idx_reader is None on clones.
  • Verified under Valgrind (0 errors, 0 leaks, eliminated previous use-after-free invalid read).

- Check mm_idx_reader_open return value before dereference and return error if null
- Introduce IdxReaderGuard to ensure reader is closed exactly once on all paths
- Store None for idx_reader in returned Aligner instead of dereferencing freed pointer
- Pass null pointer for output index when None
- Add regression tests covering index creation, mapping, cloning/dropping, failed opening, and repeated lifecycle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0