Skip to content

Commit 96e445d

Browse files
author
Rob Davies
committed
Reduce dependency on utils.h - new malloc wrapping scheme.
Remove xmalloc, xcalloc, xrealloc and xstrdup from utils.h and revert calls to the normal malloc, calloc, realloc, strdup. Add new files malloc_wrap.[ch] with the wrapper functions. malloc_wrap.h #defines malloc etc. to the wrapper, but only if USE_MALLOC_WRAPPERS has been defined. Put #include "malloc_wrap.h" in any file that uses *alloc or strdup. This is also in a #ifdef USE_MALLOC_WRAPPERS ... #endif block to make using the wrappers optional. Add -DUSE_MALLOC_WRAPPERS into the makefile so they should normally get added. This is an improvement on the previous method as we now don't need to worry about stray function calls that were not changed to the wrapped version and the code will still work even if the wrapping is disabled. Other possible methods of doing this are using malloc_hook (glibc-specific), adding -include malloc_wrap.h to the gcc command-line (somewhat gcc-specific) or making our own malloc function and using dlopen (scary). This way is probably the most portable.
1 parent 0aa7e0a commit 96e445d

37 files changed

+516
-342
lines changed

Makefile

+38-32
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
CC= gcc
22
CFLAGS= -g -Wall -O2
3+
WRAP_MALLOC= -DUSE_MALLOC_WRAPPERS
34
AR= ar
4-
DFLAGS= -DHAVE_PTHREAD
5+
DFLAGS= -DHAVE_PTHREAD $(WRAP_MALLOC)
56
LOBJS= utils.o kstring.o ksw.o bwt.o bntseq.o bwa.o bwamem.o bwamem_pair.o
67
AOBJS= QSufSort.o bwt_gen.o bwase.o bwaseqio.o bwtgap.o bwtaln.o bamlite.o \
78
is.o bwtindex.o bwape.o kopen.o pemerge.o \
89
bwtsw2_core.o bwtsw2_main.o bwtsw2_aux.o bwt_lite.o \
9-
bwtsw2_chain.o fastmap.o bwtsw2_pair.o
10+
bwtsw2_chain.o fastmap.o bwtsw2_pair.o malloc_wrap.o
1011
PROG= bwa
1112
INCLUDES=
1213
LIBS= -lm -lz -lpthread
@@ -32,39 +33,44 @@ clean:
3233
rm -f gmon.out *.o a.out $(PROG) *~ *.a
3334

3435
depend:
35-
( LC_ALL=C ; export LC_ALL; makedepend -Y -- $(CFLAGS) -- *.c )
36+
( LC_ALL=C ; export LC_ALL; makedepend -Y -- $(CFLAGS) $(DFLAGS) -- *.c )
3637

3738
# DO NOT DELETE THIS LINE -- make depend depends on it.
3839

3940
QSufSort.o: QSufSort.h
40-
bamlite.o: utils.h bamlite.h
41-
bntseq.o: bntseq.h utils.h kseq.h
42-
bwa.o: bntseq.h bwa.h bwt.h ksw.h utils.h kseq.h
43-
bwamem.o: kstring.h utils.h bwamem.h bwt.h bntseq.h bwa.h ksw.h kvec.h
44-
bwamem.o: ksort.h kbtree.h
45-
bwamem_pair.o: kstring.h utils.h bwamem.h bwt.h bntseq.h bwa.h kvec.h ksw.h
46-
bwape.o: bwtaln.h bwt.h kvec.h bntseq.h utils.h bwase.h bwa.h ksw.h khash.h
47-
bwase.o: bwase.h bntseq.h bwt.h bwtaln.h utils.h kstring.h bwa.h ksw.h
48-
bwaseqio.o: bwtaln.h bwt.h utils.h bamlite.h kseq.h
49-
bwt.o: utils.h bwt.h kvec.h
50-
bwt_gen.o: QSufSort.h utils.h
51-
bwt_lite.o: bwt_lite.h utils.h
52-
bwtaln.o: bwtaln.h bwt.h bwtgap.h utils.h bwa.h bntseq.h
53-
bwtgap.o: bwtgap.h bwt.h bwtaln.h utils.h
54-
bwtindex.o: bntseq.h bwt.h utils.h
55-
bwtsw2_aux.o: bntseq.h bwt_lite.h utils.h bwtsw2.h bwt.h kstring.h bwa.h
56-
bwtsw2_aux.o: ksw.h kseq.h ksort.h
57-
bwtsw2_chain.o: bwtsw2.h bntseq.h bwt_lite.h bwt.h utils.h ksort.h
58-
bwtsw2_core.o: bwt_lite.h bwtsw2.h bntseq.h bwt.h kvec.h utils.h khash.h
59-
bwtsw2_core.o: ksort.h
41+
bamlite.o: bamlite.h utils.h malloc_wrap.h
42+
bntseq.o: bntseq.h utils.h kseq.h malloc_wrap.h
43+
bwa.o: bntseq.h bwa.h bwt.h ksw.h malloc_wrap.h utils.h kseq.h
44+
bwamem.o: kstring.h malloc_wrap.h bwamem.h bwt.h bntseq.h bwa.h ksw.h kvec.h
45+
bwamem.o: ksort.h utils.h kbtree.h
46+
bwamem_pair.o: kstring.h malloc_wrap.h bwamem.h bwt.h bntseq.h bwa.h kvec.h
47+
bwamem_pair.o: utils.h ksw.h
48+
bwape.o: bwtaln.h bwt.h kvec.h malloc_wrap.h bntseq.h utils.h bwase.h bwa.h
49+
bwape.o: ksw.h khash.h
50+
bwase.o: bwase.h bntseq.h bwt.h bwtaln.h utils.h kstring.h malloc_wrap.h
51+
bwase.o: bwa.h ksw.h
52+
bwaseqio.o: bwtaln.h bwt.h utils.h bamlite.h malloc_wrap.h kseq.h
53+
bwt.o: utils.h bwt.h kvec.h malloc_wrap.h
54+
bwt_gen.o: QSufSort.h utils.h malloc_wrap.h
55+
bwt_lite.o: bwt_lite.h malloc_wrap.h
56+
bwtaln.o: bwtaln.h bwt.h bwtgap.h utils.h bwa.h bntseq.h malloc_wrap.h
57+
bwtgap.o: bwtgap.h bwt.h bwtaln.h malloc_wrap.h
58+
bwtindex.o: bntseq.h bwt.h utils.h malloc_wrap.h
59+
bwtsw2_aux.o: bntseq.h bwt_lite.h utils.h bwtsw2.h bwt.h kstring.h
60+
bwtsw2_aux.o: malloc_wrap.h bwa.h ksw.h kseq.h ksort.h
61+
bwtsw2_chain.o: bwtsw2.h bntseq.h bwt_lite.h bwt.h malloc_wrap.h ksort.h
62+
bwtsw2_core.o: bwt_lite.h bwtsw2.h bntseq.h bwt.h kvec.h malloc_wrap.h
63+
bwtsw2_core.o: khash.h ksort.h
6064
bwtsw2_main.o: bwt.h bwtsw2.h bntseq.h bwt_lite.h utils.h bwa.h
61-
bwtsw2_pair.o: utils.h bwt.h bntseq.h bwtsw2.h bwt_lite.h kstring.h ksw.h
62-
example.o: bwamem.h bwt.h bntseq.h bwa.h kseq.h utils.h
63-
fastmap.o: bwa.h bntseq.h bwt.h bwamem.h kvec.h utils.h kseq.h
64-
is.o: utils.h
65-
kopen.o: utils.h
66-
kstring.o: kstring.h utils.h
67-
ksw.o: ksw.h utils.h
65+
bwtsw2_pair.o: utils.h bwt.h bntseq.h bwtsw2.h bwt_lite.h kstring.h
66+
bwtsw2_pair.o: malloc_wrap.h ksw.h
67+
example.o: bwamem.h bwt.h bntseq.h bwa.h kseq.h malloc_wrap.h
68+
fastmap.o: bwa.h bntseq.h bwt.h bwamem.h kvec.h malloc_wrap.h utils.h kseq.h
69+
is.o: utils.h malloc_wrap.h
70+
kopen.o: malloc_wrap.h
71+
kstring.o: kstring.h malloc_wrap.h
72+
ksw.o: ksw.h malloc_wrap.h
6873
main.o: utils.h
69-
pemerge.o: ksw.h kseq.h utils.h kstring.h bwa.h bntseq.h bwt.h
70-
utils.o: utils.h ksort.h kseq.h
74+
malloc_wrap.o: malloc_wrap.h
75+
pemerge.o: ksw.h malloc_wrap.h kseq.h kstring.h bwa.h bntseq.h bwt.h utils.h
76+
utils.o: utils.h ksort.h malloc_wrap.h kseq.h

bamlite.c

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#include <ctype.h>
33
#include <string.h>
44
#include <stdio.h>
5-
#include "utils.h"
65
#include "bamlite.h"
76

7+
#ifdef USE_MALLOC_WRAPPERS
8+
# include "malloc_wrap.h"
9+
#endif
10+
811
/*********************
912
* from bam_endian.c *
1013
*********************/
@@ -54,7 +57,7 @@ int bam_is_be;
5457
bam_header_t *bam_header_init()
5558
{
5659
bam_is_be = bam_is_big_endian();
57-
return (bam_header_t*)xcalloc(1, sizeof(bam_header_t));
60+
return (bam_header_t*)calloc(1, sizeof(bam_header_t));
5861
}
5962

6063
void bam_header_destroy(bam_header_t *header)
@@ -87,17 +90,17 @@ bam_header_t *bam_header_read(bamFile fp)
8790
// read plain text and the number of reference sequences
8891
if (bam_read(fp, &header->l_text, 4) != 4) goto fail;
8992
if (bam_is_be) bam_swap_endian_4p(&header->l_text);
90-
header->text = (char*)xcalloc(header->l_text + 1, 1);
93+
header->text = (char*)calloc(header->l_text + 1, 1);
9194
if (bam_read(fp, header->text, header->l_text) != header->l_text) goto fail;
9295
if (bam_read(fp, &header->n_targets, 4) != 4) goto fail;
9396
if (bam_is_be) bam_swap_endian_4p(&header->n_targets);
9497
// read reference sequence names and lengths
95-
header->target_name = (char**)xcalloc(header->n_targets, sizeof(char*));
96-
header->target_len = (uint32_t*)xcalloc(header->n_targets, 4);
98+
header->target_name = (char**)calloc(header->n_targets, sizeof(char*));
99+
header->target_len = (uint32_t*)calloc(header->n_targets, 4);
97100
for (i = 0; i != header->n_targets; ++i) {
98101
if (bam_read(fp, &name_len, 4) != 4) goto fail;
99102
if (bam_is_be) bam_swap_endian_4p(&name_len);
100-
header->target_name[i] = (char*)xcalloc(name_len, 1);
103+
header->target_name[i] = (char*)calloc(name_len, 1);
101104
if (bam_read(fp, header->target_name[i], name_len) != name_len) {
102105
goto fail;
103106
}
@@ -152,7 +155,7 @@ int bam_read1(bamFile fp, bam1_t *b)
152155
if (b->m_data < b->data_len) {
153156
b->m_data = b->data_len;
154157
kroundup32(b->m_data);
155-
b->data = (uint8_t*)xrealloc(b->data, b->m_data);
158+
b->data = (uint8_t*)realloc(b->data, b->m_data);
156159
}
157160
if (bam_read(fp, b->data, b->data_len) != b->data_len) return -4;
158161
b->l_aux = b->data_len - c->n_cigar * 4 - c->l_qname - c->l_qseq - (c->l_qseq+1)/2;

bamlite.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
#include <zlib.h>
66
#include "utils.h"
77

8+
#ifdef USE_MALLOC_WRAPPERS
9+
# include "malloc_wrap.h"
10+
#endif
11+
812
typedef gzFile bamFile;
913
#define bam_open(fn, mode) xzopen(fn, mode)
1014
#define bam_dopen(fd, mode) gzdopen(fd, mode)
@@ -72,7 +76,7 @@ typedef struct {
7276
#define bam1_seqi(s, i) ((s)[(i)/2] >> 4*(1-(i)%2) & 0xf)
7377
#define bam1_aux(b) ((b)->data + (b)->core.n_cigar*4 + (b)->core.l_qname + (b)->core.l_qseq + ((b)->core.l_qseq + 1)/2)
7478

75-
#define bam_init1() ((bam1_t*)xcalloc(1, sizeof(bam1_t)))
79+
#define bam_init1() ((bam1_t*)calloc(1, sizeof(bam1_t)))
7680
#define bam_destroy1(b) do { \
7781
if (b) { free((b)->data); free(b); } \
7882
} while (0)

bntseq.c

+21-17
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#include "kseq.h"
3838
KSEQ_DECLARE(gzFile)
3939

40+
#ifdef USE_MALLOC_WRAPPERS
41+
# include "malloc_wrap.h"
42+
#endif
43+
4044
unsigned char nst_nt4_table[256] = {
4145
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4246
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
@@ -97,21 +101,21 @@ bntseq_t *bns_restore_core(const char *ann_filename, const char* amb_filename, c
97101
long long xx;
98102
int i;
99103
int scanres;
100-
bns = (bntseq_t*)xcalloc(1, sizeof(bntseq_t));
104+
bns = (bntseq_t*)calloc(1, sizeof(bntseq_t));
101105
{ // read .ann
102106
fp = xopen(fname = ann_filename, "r");
103107
scanres = fscanf(fp, "%lld%d%u", &xx, &bns->n_seqs, &bns->seed);
104108
if (scanres != 3) goto badread;
105109
bns->l_pac = xx;
106-
bns->anns = (bntann1_t*)xcalloc(bns->n_seqs, sizeof(bntann1_t));
110+
bns->anns = (bntann1_t*)calloc(bns->n_seqs, sizeof(bntann1_t));
107111
for (i = 0; i < bns->n_seqs; ++i) {
108112
bntann1_t *p = bns->anns + i;
109113
char *q = str;
110114
int c;
111115
// read gi and sequence name
112116
scanres = fscanf(fp, "%u%s", &p->gi, str);
113117
if (scanres != 2) goto badread;
114-
p->name = xstrdup(str);
118+
p->name = strdup(str);
115119
// read fasta comments
116120
while (str - q < sizeof(str) - 1 && (c = fgetc(fp)) != '\n' && c != EOF) *q++ = c;
117121
while (c != '\n' && c != EOF) c = fgetc(fp);
@@ -120,8 +124,8 @@ bntseq_t *bns_restore_core(const char *ann_filename, const char* amb_filename, c
120124
goto badread;
121125
}
122126
*q = 0;
123-
if (q - str > 1) p->anno = xstrdup(str + 1); // skip leading space
124-
else p->anno = xstrdup("");
127+
if (q - str > 1) p->anno = strdup(str + 1); // skip leading space
128+
else p->anno = strdup("");
125129
// read the rest
126130
scanres = fscanf(fp, "%lld%d%d", &xx, &p->len, &p->n_ambs);
127131
if (scanres != 3) goto badread;
@@ -137,7 +141,7 @@ bntseq_t *bns_restore_core(const char *ann_filename, const char* amb_filename, c
137141
if (scanres != 3) goto badread;
138142
l_pac = xx;
139143
xassert(l_pac == bns->l_pac && n_seqs == bns->n_seqs, "inconsistent .ann and .amb files.");
140-
bns->ambs = bns->n_holes? (bntamb1_t*)xcalloc(bns->n_holes, sizeof(bntamb1_t)) : 0;
144+
bns->ambs = bns->n_holes? (bntamb1_t*)calloc(bns->n_holes, sizeof(bntamb1_t)) : 0;
141145
for (i = 0; i < bns->n_holes; ++i) {
142146
bntamb1_t *p = bns->ambs + i;
143147
scanres = fscanf(fp, "%lld%d%s", &xx, &p->len, str);
@@ -193,11 +197,11 @@ static uint8_t *add1(const kseq_t *seq, bntseq_t *bns, uint8_t *pac, int64_t *m_
193197
int i, lasts;
194198
if (bns->n_seqs == *m_seqs) {
195199
*m_seqs <<= 1;
196-
bns->anns = (bntann1_t*)xrealloc(bns->anns, *m_seqs * sizeof(bntann1_t));
200+
bns->anns = (bntann1_t*)realloc(bns->anns, *m_seqs * sizeof(bntann1_t));
197201
}
198202
p = bns->anns + bns->n_seqs;
199-
p->name = xstrdup((char*)seq->name.s);
200-
p->anno = seq->comment.s? xstrdup((char*)seq->comment.s) : xstrdup("(null)");
203+
p->name = strdup((char*)seq->name.s);
204+
p->anno = seq->comment.s? strdup((char*)seq->comment.s) : strdup("(null)");
201205
p->gi = 0; p->len = seq->seq.l;
202206
p->offset = (bns->n_seqs == 0)? 0 : (p-1)->offset + (p-1)->len;
203207
p->n_ambs = 0;
@@ -209,7 +213,7 @@ static uint8_t *add1(const kseq_t *seq, bntseq_t *bns, uint8_t *pac, int64_t *m_
209213
} else {
210214
if (bns->n_holes == *m_holes) {
211215
(*m_holes) <<= 1;
212-
bns->ambs = (bntamb1_t*)xrealloc(bns->ambs, (*m_holes) * sizeof(bntamb1_t));
216+
bns->ambs = (bntamb1_t*)realloc(bns->ambs, (*m_holes) * sizeof(bntamb1_t));
213217
}
214218
*q = bns->ambs + bns->n_holes;
215219
(*q)->len = 1;
@@ -224,7 +228,7 @@ static uint8_t *add1(const kseq_t *seq, bntseq_t *bns, uint8_t *pac, int64_t *m_
224228
if (c >= 4) c = lrand48()&3;
225229
if (bns->l_pac == *m_pac) { // double the pac size
226230
*m_pac <<= 1;
227-
pac = xrealloc(pac, *m_pac/4);
231+
pac = realloc(pac, *m_pac/4);
228232
memset(pac + bns->l_pac/4, 0, (*m_pac - bns->l_pac)/4);
229233
}
230234
_set_pac(pac, bns->l_pac, c);
@@ -249,21 +253,21 @@ int64_t bns_fasta2bntseq(gzFile fp_fa, const char *prefix, int for_only)
249253

250254
// initialization
251255
seq = kseq_init(fp_fa);
252-
bns = (bntseq_t*)xcalloc(1, sizeof(bntseq_t));
256+
bns = (bntseq_t*)calloc(1, sizeof(bntseq_t));
253257
bns->seed = 11; // fixed seed for random generator
254258
srand48(bns->seed);
255259
m_seqs = m_holes = 8; m_pac = 0x10000;
256-
bns->anns = (bntann1_t*)xcalloc(m_seqs, sizeof(bntann1_t));
257-
bns->ambs = (bntamb1_t*)xcalloc(m_holes, sizeof(bntamb1_t));
258-
pac = xcalloc(m_pac/4, 1);
260+
bns->anns = (bntann1_t*)calloc(m_seqs, sizeof(bntann1_t));
261+
bns->ambs = (bntamb1_t*)calloc(m_holes, sizeof(bntamb1_t));
262+
pac = calloc(m_pac/4, 1);
259263
q = bns->ambs;
260264
strcpy(name, prefix); strcat(name, ".pac");
261265
fp = xopen(name, "wb");
262266
// read sequences
263267
while (kseq_read(seq) >= 0) pac = add1(seq, bns, pac, &m_pac, &m_seqs, &m_holes, &q);
264268
if (!for_only) { // add the reverse complemented sequence
265269
m_pac = (bns->l_pac * 2 + 3) / 4 * 4;
266-
pac = xrealloc(pac, m_pac/4);
270+
pac = realloc(pac, m_pac/4);
267271
memset(pac + (bns->l_pac+3)/4, 0, (m_pac - (bns->l_pac+3)/4*4) / 4);
268272
for (l = bns->l_pac - 1; l >= 0; --l, ++bns->l_pac)
269273
_set_pac(pac, bns->l_pac, 3-_get_pac(pac, l));
@@ -357,7 +361,7 @@ uint8_t *bns_get_seq(int64_t l_pac, const uint8_t *pac, int64_t beg, int64_t end
357361
if (beg >= l_pac || end <= l_pac) {
358362
int64_t k, l = 0;
359363
*len = end - beg;
360-
seq = xmalloc(end - beg);
364+
seq = malloc(end - beg);
361365
if (beg >= l_pac) { // reverse strand
362366
int64_t beg_f = (l_pac<<1) - 1 - end;
363367
int64_t end_f = (l_pac<<1) - 1 - beg;

bwa.c

+15-11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include "ksw.h"
88
#include "utils.h"
99

10+
#ifdef USE_MALLOC_WRAPPERS
11+
# include "malloc_wrap.h"
12+
#endif
13+
1014
int bwa_verbose = 3;
1115
char bwa_rg_id[256];
1216

@@ -25,10 +29,10 @@ static inline void trim_readno(kstring_t *s)
2529

2630
static inline void kseq2bseq1(const kseq_t *ks, bseq1_t *s)
2731
{ // TODO: it would be better to allocate one chunk of memory, but probably it does not matter in practice
28-
s->name = xstrdup(ks->name.s);
29-
s->comment = ks->comment.l? xstrdup(ks->comment.s) : 0;
30-
s->seq = xstrdup(ks->seq.s);
31-
s->qual = ks->qual.l? xstrdup(ks->qual.s) : 0;
32+
s->name = strdup(ks->name.s);
33+
s->comment = ks->comment.l? strdup(ks->comment.s) : 0;
34+
s->seq = strdup(ks->seq.s);
35+
s->qual = ks->qual.l? strdup(ks->qual.s) : 0;
3236
s->l_seq = strlen(s->seq);
3337
}
3438

@@ -45,7 +49,7 @@ bseq1_t *bseq_read(int chunk_size, int *n_, void *ks1_, void *ks2_)
4549
}
4650
if (n >= m) {
4751
m = m? m<<1 : 256;
48-
seqs = xrealloc(seqs, m * sizeof(bseq1_t));
52+
seqs = realloc(seqs, m * sizeof(bseq1_t));
4953
}
5054
trim_readno(&ks->name);
5155
kseq2bseq1(ks, &seqs[n]);
@@ -98,7 +102,7 @@ uint32_t *bwa_gen_cigar(const int8_t mat[25], int q, int r, int w_, int64_t l_pa
98102
tmp = rseq[i], rseq[i] = rseq[rlen - 1 - i], rseq[rlen - 1 - i] = tmp;
99103
}
100104
if (l_query == re - rb && w_ == 0) { // no gap; no need to do DP
101-
cigar = xmalloc(4);
105+
cigar = malloc(4);
102106
cigar[0] = l_query<<4 | 0;
103107
*n_cigar = 1;
104108
for (i = 0, *score = 0; i < l_query; ++i)
@@ -205,7 +209,7 @@ char *bwa_idx_infer_prefix(const char *hint)
205209
int l_hint;
206210
FILE *fp;
207211
l_hint = strlen(hint);
208-
prefix = xmalloc(l_hint + 3 + 4 + 1);
212+
prefix = malloc(l_hint + 3 + 4 + 1);
209213
strcpy(prefix, hint);
210214
strcpy(prefix + l_hint, ".64.bwt");
211215
if ((fp = fopen(prefix, "rb")) != 0) {
@@ -234,7 +238,7 @@ bwt_t *bwa_idx_load_bwt(const char *hint)
234238
if (bwa_verbose >= 1) fprintf(stderr, "[E::%s] fail to locate the index files\n", __func__);
235239
return 0;
236240
}
237-
tmp = xcalloc(strlen(prefix) + 5, 1);
241+
tmp = calloc(strlen(prefix) + 5, 1);
238242
strcat(strcpy(tmp, prefix), ".bwt"); // FM-index
239243
bwt = bwt_restore_bwt(tmp);
240244
strcat(strcpy(tmp, prefix), ".sa"); // partial suffix array (SA)
@@ -252,12 +256,12 @@ bwaidx_t *bwa_idx_load(const char *hint, int which)
252256
if (bwa_verbose >= 1) fprintf(stderr, "[E::%s] fail to locate the index files\n", __func__);
253257
return 0;
254258
}
255-
idx = xcalloc(1, sizeof(bwaidx_t));
259+
idx = calloc(1, sizeof(bwaidx_t));
256260
if (which & BWA_IDX_BWT) idx->bwt = bwa_idx_load_bwt(hint);
257261
if (which & BWA_IDX_BNS) {
258262
idx->bns = bns_restore(prefix);
259263
if (which & BWA_IDX_PAC) {
260-
idx->pac = xcalloc(idx->bns->l_pac/4+1, 1);
264+
idx->pac = calloc(idx->bns->l_pac/4+1, 1);
261265
err_fread_noeof(idx->pac, 1, idx->bns->l_pac/4+1, idx->bns->fp_pac); // concatenated 2-bit encoded sequence
262266
err_fclose(idx->bns->fp_pac);
263267
idx->bns->fp_pac = 0;
@@ -312,7 +316,7 @@ char *bwa_set_rg(const char *s)
312316
if (bwa_verbose >= 1) fprintf(stderr, "[E::%s] the read group line is not started with @RG\n", __func__);
313317
goto err_set_rg;
314318
}
315-
rg_line = xstrdup(s);
319+
rg_line = strdup(s);
316320
bwa_escape(rg_line);
317321
if ((p = strstr(rg_line, "\tID:")) == 0) {
318322
if (bwa_verbose >= 1) fprintf(stderr, "[E::%s] no ID at the read group line\n", __func__);

0 commit comments

Comments
 (0)