Skip to content

Commit

Permalink
Remove potential memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
nickjcroucher committed Apr 22, 2024
1 parent abb28ac commit a41030f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/branch_sequences.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ int get_list_of_snp_indices_which_fall_in_downstream_recombinations(int ** curre

//make sure that the index begins at start of block
int beginning_j = current_index;
for(beginning_j = current_index; snp_locations[beginning_j] < current_block_coordinates[0][i];beginning_j++)
for(int beginning_j = current_index; snp_locations[beginning_j] < current_block_coordinates[0][i];beginning_j++)
{
}

Expand Down Expand Up @@ -310,7 +310,9 @@ void generate_branch_sequences(newick_node *node, FILE *vcf_file_pointer,int * s
int branch_genome_size = 0;
int number_of_branch_snps = 0;

// Get SNP alleles for node from reconstruction phylip
char * node_sequence = (char *) calloc((number_of_snps +1),sizeof(char));
get_sequence_for_sample_name(node_sequence, node->taxon);

if (node->childNum == 0)
{
Expand Down Expand Up @@ -344,9 +346,6 @@ void generate_branch_sequences(newick_node *node, FILE *vcf_file_pointer,int * s
// Retrieve child sequences from store
get_sequence_for_sample_name(child_sequences[child_counter], child->node->taxon);
child_nodes[child_counter] = child->node;

// Remove from store as cannot be children of any other nodes
// TO DO

char delimiter_string[3] = {" "};
concat_strings_created_with_malloc(node->taxon_names, delimiter_string);
Expand All @@ -357,8 +356,6 @@ void generate_branch_sequences(newick_node *node, FILE *vcf_file_pointer,int * s
}

// Get sequence reconstructed at internal node
node_sequence = (char *) calloc((number_of_snps +1),sizeof(char));
get_sequence_for_sample_name(node_sequence, node->taxon);
branch_genome_size = calculate_size_of_genome_without_gaps(node_sequence, 0,number_of_snps, length_of_original_genome);
set_genome_length_without_gaps_for_sample(node->taxon,branch_genome_size);

Expand Down Expand Up @@ -401,6 +398,7 @@ void generate_branch_sequences(newick_node *node, FILE *vcf_file_pointer,int * s
free(branch_snp_sequence);
free(branch_snp_ancestor_sequence);
free(branches_snp_sites);
free(child_sequences);

}

Expand Down Expand Up @@ -1255,5 +1253,8 @@ int calculate_genome_length_excluding_blocks_and_gaps(char * sequence, int lengt
}
}

free(filtered_start_coords);
free(filtered_end_coords);

return genome_length;
}
1 change: 0 additions & 1 deletion src/csv_of_snp_sites.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ void create_csv_of_snp_sites(char filename[], int number_of_snps, char ** bases_
// Indices run consecutively, rather than using SNP locations in whole genome alignment
// This is because pyjar reconstructs only the polymorphic sites, not the whole sequences
indexed_pattern* base_pattern_indices = malloc(number_of_snps * sizeof(indexed_pattern));
i = 0;
for (i = 0; i < number_of_snps; i++)
{
base_pattern_indices[i].pattern = bases_for_snps[i];
Expand Down
1 change: 0 additions & 1 deletion src/parse_phylip.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,6 @@ void load_sequences_from_multifasta_file(char filename[])
get_sample_names_for_header(filename, phylip_sample_names, num_samples);

int l;
i = 0;
int sequence_number = 0;

gzFile fp;
Expand Down

0 comments on commit a41030f

Please sign in to comment.