From: Heng Li Date: Sun, 10 Mar 2013 00:12:41 +0000 (-0800) Subject: Merge pull request #30 from leecbaker/master X-Git-Url: https://git.donarmstrong.com/?p=samtools.git;a=commitdiff_plain;h=dbc7644895129440a9b1d7b448d5d8046b7af5d4;hp=c857677f2a3af9da652dd6b5fc97249368e6e7d8 Merge pull request #30 from leecbaker/master Fixed several small memory leaks. --- diff --git a/bam_index.c b/bam_index.c index d6b94e2..f916e04 100644 --- a/bam_index.c +++ b/bam_index.c @@ -464,6 +464,7 @@ bam_index_t *bam_index_load(const char *fn) strcat(strcpy(fnidx, fn), ".bai"); fprintf(stderr, "[bam_index_load] attempting to download the remote index file.\n"); download_from_remote(fnidx); + free(fnidx); idx = bam_index_load_local(fn); } if (idx == 0) fprintf(stderr, "[bam_index_load] fail to load BAM index.\n"); @@ -494,6 +495,7 @@ int bam_index_build2(const char *fn, const char *_fnidx) if (fpidx == 0) { fprintf(stderr, "[bam_index_build2] fail to create the index file.\n"); free(fnidx); + bam_index_destroy(idx); return -1; } bam_index_save(idx, fpidx); diff --git a/bcftools/index.c b/bcftools/index.c index 014856d..a7db24f 100644 --- a/bcftools/index.c +++ b/bcftools/index.c @@ -259,6 +259,7 @@ int bcf_idx_build2(const char *fn, const char *_fnidx) if (fpidx == 0) { fprintf(stderr, "[bcf_idx_build2] fail to create the index file.\n"); free(fnidx); + bcf_idx_destroy(idx); return -1; } bcf_idx_save(idx, fpidx); diff --git a/bcftools/vcf.c b/bcftools/vcf.c index bc11084..e8526a3 100644 --- a/bcftools/vcf.c +++ b/bcftools/vcf.c @@ -30,7 +30,12 @@ bcf_hdr_t *vcf_hdr_read(bcf_t *bp) memset(&smpl, 0, sizeof(kstring_t)); while (ks_getuntil(v->ks, '\n', &v->line, &dret) >= 0) { if (v->line.l < 2) continue; - if (v->line.s[0] != '#') return 0; // no sample line + if (v->line.s[0] != '#') { + free(meta.s); + free(smpl.s); + free(h); + return 0; // no sample line + } if (v->line.s[0] == '#' && v->line.s[1] == '#') { kputsn(v->line.s, v->line.l, &meta); kputc('\n', &meta); } else if (v->line.s[0] == '#') { diff --git a/sam_header.c b/sam_header.c index a1b5181..ddc2c38 100644 --- a/sam_header.c +++ b/sam_header.c @@ -366,6 +366,7 @@ static HeaderLine *sam_header_line_parse(const char *headerLine) while (*to && *to=='\t') to++; if ( to-from != 1 ) { debug("[sam_header_line_parse] multiple tabs on line [%s] (%d)\n", headerLine,(int)(to-from)); + free(hline); return 0; } from = to;