From c4170d90ab5a5f7008f6969bdce47d7a21761c56 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Sat, 23 Nov 2013 13:12:24 -0500 Subject: better allocation of memory, make sure to free other memory --- kmer_utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'kmer_utils.c') 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; } -- cgit v1.2.3