X-Git-Url: https://git.donarmstrong.com/?p=rsem.git;a=blobdiff_plain;f=sam%2Fbam_index.c;fp=sam%2Fbam_index.c;h=f916e0461dca145499303db8edb011e6db86f793;hp=9610a2656031657b796abc68bf32c1b6f1564745;hb=dbcf1cfb8ad1086c21d64e249f012809403e7ddc;hpb=58d504aaf36ae486b1dba6d03e0e9f1c25855037 diff --git a/sam/bam_index.c b/sam/bam_index.c index 9610a26..f916e04 100644 --- a/sam/bam_index.c +++ b/sam/bam_index.c @@ -159,9 +159,14 @@ bam_index_t *bam_index_core(bamFile fp) bam1_core_t *c; uint64_t save_off, last_off, n_mapped, n_unmapped, off_beg, off_end, n_no_coor; + h = bam_header_read(fp); + if(h == 0) { + fprintf(stderr, "[bam_index_core] Invalid BAM header."); + return NULL; + } + idx = (bam_index_t*)calloc(1, sizeof(bam_index_t)); b = (bam1_t*)calloc(1, sizeof(bam1_t)); - h = bam_header_read(fp); c = &b->core; idx->n = h->n_targets; @@ -459,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"); @@ -489,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);