alignpairedend: fixed the worst memory leak and the handling of the case
where 0 common kmers are found
This commit is contained in:
@ -67,11 +67,14 @@ Obi_ali_p kmer_similarity(Obiview_p view1, OBIDMS_column_p column1, index_t idx1
|
||||
Obiview_p view2, OBIDMS_column_p column2, index_t idx2, index_t elt_idx2,
|
||||
OBIDMS_column_p qual_col1, OBIDMS_column_p qual_col2,
|
||||
uint8_t kmer_size,
|
||||
int32_t* kmer_pos_array, int32_t* kmer_pos_array_height_p,
|
||||
int32_t* shift_array, int32_t* shift_array_height_p,
|
||||
int32_t* shift_count_array, int32_t* shift_count_array_length_p,
|
||||
int32_t** kmer_pos_array_p, int32_t* kmer_pos_array_height_p,
|
||||
int32_t** shift_array_p, int32_t* shift_array_height_p,
|
||||
int32_t** shift_count_array_p, int32_t* shift_count_array_length_p,
|
||||
bool build_consensus)
|
||||
{
|
||||
int32_t* kmer_pos_array;
|
||||
int32_t* shift_array;
|
||||
int32_t* shift_count_array;
|
||||
Obi_ali_p ali = NULL;
|
||||
int i, j;
|
||||
bool switched_seqs;
|
||||
@ -191,11 +194,11 @@ Obi_ali_p kmer_similarity(Obiview_p view1, OBIDMS_column_p column1, index_t idx1
|
||||
total_len = len1 + len2 + 1; // +1 for shift 0
|
||||
|
||||
// Allocate or reallocate memory for the array of shift counts if necessary
|
||||
if (shift_count_array == NULL)
|
||||
if (*shift_count_array_p == NULL)
|
||||
{
|
||||
shift_count_array_length = total_len;
|
||||
shift_count_array = (int32_t*) malloc(shift_count_array_length * sizeof(int32_t));
|
||||
if (shift_count_array == NULL)
|
||||
*shift_count_array_p = (int32_t*) malloc(shift_count_array_length * sizeof(int32_t));
|
||||
if (*shift_count_array_p == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError computing the kmer similarity between two sequences: error allocating memory");
|
||||
@ -205,8 +208,8 @@ Obi_ali_p kmer_similarity(Obiview_p view1, OBIDMS_column_p column1, index_t idx1
|
||||
else if (total_len >= shift_count_array_length)
|
||||
{
|
||||
shift_count_array_length = total_len;
|
||||
shift_count_array = (int32_t*) realloc(shift_count_array, shift_count_array_length * sizeof(int32_t));
|
||||
if (shift_count_array == NULL)
|
||||
*shift_count_array_p = (int32_t*) realloc(*shift_count_array_p, shift_count_array_length * sizeof(int32_t));
|
||||
if (*shift_count_array_p == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError computing the kmer similarity between two sequences: error allocating memory");
|
||||
@ -215,11 +218,11 @@ Obi_ali_p kmer_similarity(Obiview_p view1, OBIDMS_column_p column1, index_t idx1
|
||||
}
|
||||
|
||||
// Allocate or reallocate memory for the array of shifts if necessary
|
||||
if (shift_array == NULL)
|
||||
if (*shift_array_p == NULL)
|
||||
{
|
||||
shift_array_height = total_len;
|
||||
shift_array = (int32_t*) malloc(ARRAY_LENGTH * shift_array_height * sizeof(int32_t));
|
||||
if (shift_array == NULL)
|
||||
*shift_array_p = (int32_t*) malloc(ARRAY_LENGTH * shift_array_height * sizeof(int32_t));
|
||||
if (*shift_array_p == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError computing the kmer similarity between two sequences: error allocating memory");
|
||||
@ -229,8 +232,8 @@ Obi_ali_p kmer_similarity(Obiview_p view1, OBIDMS_column_p column1, index_t idx1
|
||||
else if (len1 >= shift_array_height)
|
||||
{
|
||||
shift_array_height = total_len;
|
||||
shift_array = (int32_t*) realloc(shift_array, ARRAY_LENGTH * shift_array_height * sizeof(int32_t));
|
||||
if (shift_array == NULL)
|
||||
*shift_array_p = (int32_t*) realloc(*shift_array_p, ARRAY_LENGTH * shift_array_height * sizeof(int32_t));
|
||||
if (*shift_array_p == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError computing the kmer similarity between two sequences: error allocating memory");
|
||||
@ -239,11 +242,11 @@ Obi_ali_p kmer_similarity(Obiview_p view1, OBIDMS_column_p column1, index_t idx1
|
||||
}
|
||||
|
||||
// Allocate or reallocate memory for the array of positions if necessary
|
||||
if (kmer_pos_array == NULL)
|
||||
if (*kmer_pos_array_p == NULL)
|
||||
{
|
||||
kmer_pos_array_height = len1;
|
||||
kmer_pos_array = (int32_t*) malloc(ARRAY_LENGTH * kmer_pos_array_height * sizeof(int32_t));
|
||||
if (kmer_pos_array == NULL)
|
||||
*kmer_pos_array_p = (int32_t*) malloc(ARRAY_LENGTH * kmer_pos_array_height * sizeof(int32_t));
|
||||
if (*kmer_pos_array_p == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError computing the kmer similarity between two sequences: error allocating memory");
|
||||
@ -253,8 +256,8 @@ Obi_ali_p kmer_similarity(Obiview_p view1, OBIDMS_column_p column1, index_t idx1
|
||||
else if (len1 >= kmer_pos_array_height)
|
||||
{
|
||||
kmer_pos_array_height = len1;
|
||||
kmer_pos_array = (int32_t*) realloc(kmer_pos_array, ARRAY_LENGTH * kmer_pos_array_height * sizeof(int32_t));
|
||||
if (kmer_pos_array == NULL)
|
||||
*kmer_pos_array_p = (int32_t*) realloc(*kmer_pos_array_p, ARRAY_LENGTH * kmer_pos_array_height * sizeof(int32_t));
|
||||
if (*kmer_pos_array_p == NULL)
|
||||
{
|
||||
obi_set_errno(OBI_MALLOC_ERROR);
|
||||
obidebug(1, "\nError computing the kmer similarity between two sequences: error allocating memory");
|
||||
@ -262,6 +265,10 @@ Obi_ali_p kmer_similarity(Obiview_p view1, OBIDMS_column_p column1, index_t idx1
|
||||
}
|
||||
}
|
||||
|
||||
shift_count_array = *shift_count_array_p;
|
||||
shift_array = *shift_array_p;
|
||||
kmer_pos_array = *kmer_pos_array_p;
|
||||
|
||||
// Initialize all positions to -1
|
||||
for (i=0; i<(ARRAY_LENGTH * kmer_pos_array_height); i++)
|
||||
kmer_pos_array[i] = -1;
|
||||
|
Reference in New Issue
Block a user