r129: fixed memory leak caused by qualities

This commit is contained in:
Heng Li 2017-06-30 23:48:00 -04:00
parent 10910b72d1
commit 41efd03d7a
6 changed files with 24 additions and 8 deletions

4
bseq.c
View File

@ -32,7 +32,7 @@ void bseq_close(bseq_file_t *fp)
free(fp); free(fp);
} }
bseq1_t *bseq_read(bseq_file_t *fp, int chunk_size, int *n_) bseq1_t *bseq_read(bseq_file_t *fp, int chunk_size, int with_qual, int *n_)
{ {
int size = 0, m, n; int size = 0, m, n;
bseq1_t *seqs; bseq1_t *seqs;
@ -48,7 +48,7 @@ bseq1_t *bseq_read(bseq_file_t *fp, int chunk_size, int *n_)
s = &seqs[n]; s = &seqs[n];
s->name = strdup(ks->name.s); s->name = strdup(ks->name.s);
s->seq = strdup(ks->seq.s); s->seq = strdup(ks->seq.s);
s->qual = ks->qual.l? strdup(ks->qual.s) : 0; s->qual = with_qual && ks->qual.l? strdup(ks->qual.s) : 0;
s->l_seq = ks->seq.l; s->l_seq = ks->seq.l;
size += seqs[n++].l_seq; size += seqs[n++].l_seq;
if (size >= chunk_size) break; if (size >= chunk_size) break;

2
bseq.h
View File

@ -13,7 +13,7 @@ typedef struct {
bseq_file_t *bseq_open(const char *fn); bseq_file_t *bseq_open(const char *fn);
void bseq_close(bseq_file_t *fp); void bseq_close(bseq_file_t *fp);
bseq1_t *bseq_read(bseq_file_t *fp, int chunk_size, int *n_); bseq1_t *bseq_read(bseq_file_t *fp, int chunk_size, int with_qual, int *n_);
int bseq_eof(bseq_file_t *fp); int bseq_eof(bseq_file_t *fp);
extern unsigned char seq_nt4_table[256]; extern unsigned char seq_nt4_table[256];

View File

@ -217,7 +217,7 @@ static void *worker_pipeline(void *shared, int step, void *in)
step_t *s; step_t *s;
if (p->sum_len > p->batch_size) return 0; if (p->sum_len > p->batch_size) return 0;
s = (step_t*)calloc(1, sizeof(step_t)); s = (step_t*)calloc(1, sizeof(step_t));
s->seq = bseq_read(p->fp, p->mini_batch_size, &s->n_seq); // read a mini-batch s->seq = bseq_read(p->fp, p->mini_batch_size, 0, &s->n_seq); // read a mini-batch
if (s->seq) { if (s->seq) {
uint32_t old_m, m; uint32_t old_m, m;
uint64_t sum_len, old_max_len, max_len; uint64_t sum_len, old_max_len, max_len;

2
main.c
View File

@ -10,7 +10,7 @@
#include "minimap.h" #include "minimap.h"
#include "mmpriv.h" #include "mmpriv.h"
#define MM_VERSION "2.0-r126-pre" #define MM_VERSION "2.0-r129-pre"
void liftrlimit() void liftrlimit()
{ {

3
map.c
View File

@ -304,7 +304,7 @@ static void *worker_pipeline(void *shared, int step, void *in)
if (step == 0) { // step 0: read sequences if (step == 0) { // step 0: read sequences
step_t *s; step_t *s;
s = (step_t*)calloc(1, sizeof(step_t)); s = (step_t*)calloc(1, sizeof(step_t));
s->seq = bseq_read(p->fp, p->mini_batch_size, &s->n_seq); s->seq = bseq_read(p->fp, p->mini_batch_size, !!(p->opt->flag & MM_F_OUT_SAM), &s->n_seq);
if (s->seq) { if (s->seq) {
s->p = p; s->p = p;
for (i = 0; i < s->n_seq; ++i) for (i = 0; i < s->n_seq; ++i)
@ -339,6 +339,7 @@ static void *worker_pipeline(void *shared, int step, void *in)
} }
free(s->reg[i]); free(s->reg[i]);
free(s->seq[i].seq); free(s->seq[i].name); free(s->seq[i].seq); free(s->seq[i].name);
if (s->seq[i].qual) free(s->seq[i].qual);
} }
free(s->reg); free(s->n_reg); free(s->seq); free(s->reg); free(s->n_reg); free(s->seq);
if (mm_verbose >= 3) if (mm_verbose >= 3)

View File

@ -5,7 +5,7 @@
minimap2 - mapping and alignment between collections of DNA sequences minimap2 - mapping and alignment between collections of DNA sequences
.SH SYNOPSIS .SH SYNOPSIS
* Index the target sequences (optional): * Indexing the target sequences (optional):
.RS 4 .RS 4
minimap2 minimap2
.RB [ -H ] .RB [ -H ]
@ -13,12 +13,14 @@ minimap2
.IR kmer ] .IR kmer ]
.RB [ -w .RB [ -w
.IR miniWinSize ] .IR miniWinSize ]
.RB [ -I
.IR batchSize ]
.B -d .B -d
.I target.mmi .I target.mmi
.I target.fa .I target.fa
.RE .RE
* Align with CIGAR: * Long-read alignment with CIGAR:
.RS 4 .RS 4
minimap2 minimap2
.B -b .B -b
@ -43,6 +45,19 @@ minimap2
.I output.paf .I output.paf
.RE .RE
* Long read overlap without CIGAR:
.RS 4
minimap2
.B -x
.R ava10k
.RB [ -t
.IR nThreads ]
.I target.fa
.I query.fa
>
.I output.paf
.RE
.SH DESCRIPTION .SH DESCRIPTION
.PP .PP
Minimap2 is a fast sequence mapping and alignment program that can find Minimap2 is a fast sequence mapping and alignment program that can find