From 17593028290418ac0a879cbcafcaef5f6edbe3cd Mon Sep 17 00:00:00 2001 From: Celine Mercier Date: Sat, 6 Jul 2019 16:31:19 +0200 Subject: [PATCH] C: ecotag: fixed 2 memory bugs --- src/obi_ecotag.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/obi_ecotag.c b/src/obi_ecotag.c index 33503b5..ca745e7 100755 --- a/src/obi_ecotag.c +++ b/src/obi_ecotag.c @@ -232,6 +232,7 @@ int obi_ecotag(const char* dms_name, const int* lca_array; index_t* best_match_array; char* best_match_ids; + char* best_match_ids_to_store; int32_t best_match_ids_length; int best_match_count; 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) + // TODO check same dms if (strcmp((query_seq_column->header)->indexer_name, (ref_seq_column->header)->indexer_name) == 0) same_indexer = true; else @@ -504,7 +506,7 @@ int obi_ecotag(const char* dms_name, id_len = strlen(id); // 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 = (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; else lca_name = lca->name; + best_match_ids_to_store = best_match_ids; } else { assigned = false; lca_name = OBIStr_NA; lca_taxid = OBIInt_NA; - best_match_ids = OBITuple_NA; + best_match_ids_to_store = OBITuple_NA; score = OBIFloat_NA; } @@ -614,7 +617,7 @@ int obi_ecotag(const char* dms_name, assigned_taxid_column, lca_taxid, assigned_name_column, lca_name, 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 ) < 0) return -1;