diff --git a/fastmap.c b/fastmap.c index 3e8e3b4..69dbcbe 100644 --- a/fastmap.c +++ b/fastmap.c @@ -90,9 +90,12 @@ int main_mem(int argc, char *argv[]) bwa_fill_scmat(opt->a, opt->b, opt->mat); if ((idx = bwa_idx_load(argv[optind], BWA_IDX_ALL)) == 0) return 1; // FIXME: memory leak - bwa_print_sam_hdr(idx->bns, rg_line); ko = kopen(argv[optind + 1], &fd); + if (ko == 0) { + if (bwa_verbose >= 1) fprintf(stderr, "[E::%s] fail to open file `%s'.\n", __func__, argv[optind + 1]); + return 1; + } fp = gzdopen(fd, "r"); ks = kseq_init(fp); if (optind + 2 < argc) { @@ -101,11 +104,16 @@ int main_mem(int argc, char *argv[]) fprintf(stderr, "[W::%s] when '-p' is in use, the second query file will be ignored.\n", __func__); } else { ko2 = kopen(argv[optind + 2], &fd2); + if (ko2 == 0) { + if (bwa_verbose >= 1) fprintf(stderr, "[E::%s] fail to open file `%s'.\n", __func__, argv[optind + 2]); + return 1; + } fp2 = gzdopen(fd2, "r"); ks2 = kseq_init(fp2); opt->flag |= MEM_F_PE; } } + bwa_print_sam_hdr(idx->bns, rg_line); while ((seqs = bseq_read(opt->chunk_size * opt->n_threads, &n, ks, ks2)) != 0) { int64_t size = 0; if ((opt->flag & MEM_F_PE) && (n&1) == 1) { diff --git a/kopen.c b/kopen.c index 8887932..c0bc975 100644 --- a/kopen.c +++ b/kopen.c @@ -292,14 +292,14 @@ void *kopen(const char *fn, int *_fd) #else *_fd = open(fn, O_RDONLY); #endif - if (*_fd) { + if (*_fd >= 0) { aux = calloc(1, sizeof(koaux_t)); aux->type = KO_FILE; aux->fd = *_fd; } } } - *_fd = aux->fd; + if (aux) *_fd = aux->fd; return aux; } diff --git a/main.c b/main.c index cb4289c..d40d996 100644 --- a/main.c +++ b/main.c @@ -3,7 +3,7 @@ #include "utils.h" #ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "0.7.4-r388-beta" +#define PACKAGE_VERSION "0.7.4-r389-beta" #endif int bwa_fa2pac(int argc, char *argv[]); @@ -92,5 +92,5 @@ int main(int argc, char *argv[]) fprintf(stderr, " %s", argv[i]); fprintf(stderr, "\n[%s] Real time: %.3f sec; CPU: %.3f sec\n", __func__, realtime() - t_real, cputime()); } - return 0; + return ret; }