diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2013-11-23 13:12:24 -0500 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2013-11-23 13:12:24 -0500 |
commit | c4170d90ab5a5f7008f6969bdce47d7a21761c56 (patch) | |
tree | daf1f37cecb78c12ffe8b77eef10436575b406ed | |
parent | cdb94d95429edf6d1f68ee3954cb2feb843f02e2 (diff) |
better allocation of memory, make sure to free other memory
-rw-r--r-- | kmer_total_count.c | 2 | ||||
-rw-r--r-- | kmer_utils.c | 7 |
2 files changed, 7 insertions, 2 deletions
diff --git a/kmer_total_count.c b/kmer_total_count.c index 57d4fcc..f15b69c 100644 --- a/kmer_total_count.c +++ b/kmer_total_count.c @@ -116,5 +116,7 @@ int main(int argc, char **argv) { } } } + + free(counts); return EXIT_SUCCESS; } diff --git a/kmer_utils.c b/kmer_utils.c index b29cd24..6736279 100644 --- a/kmer_utils.c +++ b/kmer_utils.c @@ -52,7 +52,7 @@ inline unsigned long num_to_index(const char *str, const int kmer, const long er char *index_to_kmer(unsigned long long index, long kmer) { int num_array[64]; - char *ret = malloc(64); + char *ret = calloc(64, sizeof(char)); if(ret == NULL) exit(EXIT_FAILURE); @@ -117,7 +117,7 @@ unsigned long long * get_kmer_counts_from_file(const char *fn, const unsigned in const unsigned long width = pow_four(kmer); // malloc our return array - unsigned long long * counts = malloc((width+ 1) * sizeof(unsigned long long)); + unsigned long long * counts = calloc((width+ 1), sizeof(unsigned long long)); if(counts == NULL) { fprintf(stderr, strerror(errno)); exit(EXIT_FAILURE); @@ -186,5 +186,8 @@ unsigned long long * get_kmer_counts_from_file(const char *fn, const unsigned in } free(line); + free(str); + fclose(fh); + return counts; } |