Skip to content

Commit

Permalink
Fixed small memory leak in WFA2lib
Browse files Browse the repository at this point in the history
  • Loading branch information
smarco committed Jul 11, 2022
1 parent 164c1d5 commit 63a0da0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
17 changes: 13 additions & 4 deletions src/common/wflign/deps/WFA/wavefront/wavefront_aligner.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ void wavefront_aligner_init_alignment(
// Allocate subsidiary aligners
wf_aligner->aligner_forward = wavefront_aligner_new(&subsidiary_attr);
wf_aligner->aligner_reverse = wavefront_aligner_new(&subsidiary_attr);
// Allocate global CIGAR
cigar_allocate(&wf_aligner->bialign_cigar,
2*(pattern_length+text_length),wf_aligner->mm_allocator);
} else {
wf_aligner->aligner_forward = NULL;
wf_aligner->aligner_reverse = NULL;
Expand Down Expand Up @@ -295,12 +298,15 @@ void wavefront_aligner_reap(
// Padded sequences
if (wf_aligner->sequences != NULL) {
strings_padded_delete(wf_aligner->sequences);
wf_aligner->sequences = NULL;
}
// Wavefront components
wavefront_components_reap(&wf_aligner->wf_components);
// Subsidiary aligners
if (wf_aligner->aligner_forward != NULL) wavefront_aligner_reap(wf_aligner->aligner_forward);
if (wf_aligner->aligner_reverse != NULL) wavefront_aligner_reap(wf_aligner->aligner_reverse);
if (wf_aligner->bidirectional_alignment) {
wavefront_aligner_reap(wf_aligner->aligner_forward);
wavefront_aligner_reap(wf_aligner->aligner_reverse);
}
// Slab
wavefront_slab_reap(wf_aligner->wavefront_slab);
}
Expand All @@ -316,8 +322,11 @@ void wavefront_aligner_delete(
// Wavefront components
wavefront_components_free(&wf_aligner->wf_components);
// Subsidiary aligners
if (wf_aligner->aligner_forward != NULL) wavefront_aligner_delete(wf_aligner->aligner_forward);
if (wf_aligner->aligner_reverse != NULL) wavefront_aligner_delete(wf_aligner->aligner_reverse);
if (wf_aligner->bidirectional_alignment) {
wavefront_aligner_delete(wf_aligner->aligner_forward);
wavefront_aligner_delete(wf_aligner->aligner_reverse);
cigar_free(&wf_aligner->bialign_cigar);
}
// CIGAR
if (!score_only) {
cigar_free(&wf_aligner->cigar);
Expand Down
1 change: 1 addition & 0 deletions src/common/wflign/deps/WFA/wavefront/wavefront_aligner.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ typedef struct _wavefront_aligner_t {
wavefront_aligner_t* aligner_forward; // Forward aligner
wavefront_aligner_t* aligner_reverse; // Reverse aligner
wf_bialign_breakpoint_t bialign_breakpoint; // Breakpoint of two wavefronts (bialigner)
cigar_t bialign_cigar; // Global BiWFA Alignment CIGAR
// CIGAR
cigar_t cigar; // Alignment CIGAR
// MM
Expand Down
10 changes: 4 additions & 6 deletions src/common/wflign/deps/WFA/wavefront/wavefront_bialign.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,17 +617,15 @@ void wavefront_bialign(
if (wf_aligner->alignment_scope == compute_score) {
wavefront_bialign_compute_score(wf_aligner,pattern,pattern_length,text,text_length);
} else {
cigar_t cigar;
cigar_allocate(&cigar,2*(pattern_length+text_length),wf_aligner->mm_allocator);
SWAP(wf_aligner->cigar,wf_aligner->bialign_cigar);
cigar_resize(&wf_aligner->bialign_cigar,2*(pattern_length+text_length));
// Bidirectional alignment
wavefront_bialign_alignment(wf_aligner,
pattern,pattern_length,text,text_length,
&wf_aligner->alignment_form,
affine_matrix_M,affine_matrix_M,
INT_MAX,&cigar,0);
// Swap and free cigar
SWAP(wf_aligner->cigar,cigar);
cigar_free(&cigar);
INT_MAX,&wf_aligner->bialign_cigar,0);
SWAP(wf_aligner->cigar,wf_aligner->bialign_cigar);
}
}

0 comments on commit 63a0da0

Please sign in to comment.