C: ecotag: fixed 2 memory bugs

This commit is contained in:
Celine Mercier
2019-07-06 16:31:19 +02:00
parent 86bfa96fbe
commit 1759302829

View File

@ -232,6 +232,7 @@ int obi_ecotag(const char* dms_name,
const int* lca_array; const int* lca_array;
index_t* best_match_array; index_t* best_match_array;
char* best_match_ids; char* best_match_ids;
char* best_match_ids_to_store;
int32_t best_match_ids_length; int32_t best_match_ids_length;
int best_match_count; int best_match_count;
int buffer_size; int buffer_size;
@ -393,6 +394,7 @@ int obi_ecotag(const char* dms_name,
} }
// Check if the sequence columns share the same indexer (allows for quick checking of sequence equality) // Check if the sequence columns share the same indexer (allows for quick checking of sequence equality)
// TODO check same dms
if (strcmp((query_seq_column->header)->indexer_name, (ref_seq_column->header)->indexer_name) == 0) if (strcmp((query_seq_column->header)->indexer_name, (ref_seq_column->header)->indexer_name) == 0)
same_indexer = true; same_indexer = true;
else else
@ -504,7 +506,7 @@ int obi_ecotag(const char* dms_name,
id_len = strlen(id); id_len = strlen(id);
// Grow ids array if needed // Grow ids array if needed
if ((best_match_ids_length+id_len+1) >= best_match_ids_buffer_size) while ((best_match_ids_length+id_len+1) >= best_match_ids_buffer_size)
{ {
best_match_ids_buffer_size = best_match_ids_buffer_size*2; best_match_ids_buffer_size = best_match_ids_buffer_size*2;
best_match_ids = (char*) realloc(best_match_ids, best_match_ids_buffer_size*sizeof(char)); best_match_ids = (char*) realloc(best_match_ids, best_match_ids_buffer_size*sizeof(char));
@ -599,13 +601,14 @@ int obi_ecotag(const char* dms_name,
lca_name = lca->preferred_name; lca_name = lca->preferred_name;
else else
lca_name = lca->name; lca_name = lca->name;
best_match_ids_to_store = best_match_ids;
} }
else else
{ {
assigned = false; assigned = false;
lca_name = OBIStr_NA; lca_name = OBIStr_NA;
lca_taxid = OBIInt_NA; lca_taxid = OBIInt_NA;
best_match_ids = OBITuple_NA; best_match_ids_to_store = OBITuple_NA;
score = OBIFloat_NA; score = OBIFloat_NA;
} }
@ -614,7 +617,7 @@ int obi_ecotag(const char* dms_name,
assigned_taxid_column, lca_taxid, assigned_taxid_column, lca_taxid,
assigned_name_column, lca_name, assigned_name_column, lca_name,
assigned_status_column, assigned, assigned_status_column, assigned,
best_match_column, best_match_ids, best_match_ids_length, best_match_column, best_match_ids_to_store, best_match_ids_length,
score_column, best_score score_column, best_score
) < 0) ) < 0)
return -1; return -1;