- idx->index = (khash_t(i)**)calloc(idx->n, sizeof(void*));
- idx->index2 = (bam_lidx_t*)calloc(idx->n, sizeof(bam_lidx_t));
+ if ((idx->index = (khash_t(i)**)calloc(idx->n, sizeof(void*))) == NULL) {
+ fprintf(stderr, "[%s] failed to allocate bam_index bin hash.\n", __func__);
+ free(idx);
+ fclose(fp);
+ return NULL;
+ }
+ if ((idx->index2 = (bam_lidx_t*)calloc(idx->n, sizeof(bam_lidx_t))) == NULL) {
+ fprintf(stderr, "[%s] failed to allocate bam_index linear index.\n", __func__);
+ free(idx->index);
+ free(idx);
+ fclose(fp);
+ return NULL;
+ }
+