Skip to content

Commit 6a28a1e

Browse files
committed
fix some possible memory leaks
#392
1 parent 06d8679 commit 6a28a1e

7 files changed

+46
-3
lines changed

Diff for: src/peprocessor.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ PairEndProcessor::~PairEndProcessor() {
5858
delete mRightReadPool;
5959
mRightReadPool = NULL;
6060
}
61+
for(int t=0; t<mOptions->thread; t++){
62+
delete mLeftInputLists[t];
63+
delete mRightInputLists[t];
64+
}
65+
delete[] mLeftInputLists;
66+
delete[] mRightInputLists;
6167
}
6268

6369
void PairEndProcessor::initOutput() {

Diff for: src/read.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ Read* Read::reverseComplement(){
5656
string seq = Sequence::reverseComplement(mSeq);
5757
string qual;
5858
qual.assign(mQuality->rbegin(), mQuality->rend());
59-
string* strand=new string("+");
6059
return new Read(mName->c_str(), seq.c_str(), "+", qual.c_str());
6160
}
6261

Diff for: src/readpool.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,15 @@ bool ReadPool::input(int tid, Read* data) {
3131
}
3232

3333
void ReadPool::cleanup() {
34-
//TODO: delete unused pooled Reads.
35-
//But since this is only called when the program exits, the one-by-one deletion can be skipped to save time
34+
for(int t=0; t<mOptions->thread; t++) {
35+
while(mBufferLists[t]->canBeConsumed()) {
36+
Read* r = mBufferLists[t]->consume();
37+
mConsumed++;
38+
delete r;
39+
}
40+
delete mBufferLists[t];
41+
}
42+
delete[] mBufferLists;
3643
}
3744

3845
void ReadPool::initBufferLists() {

Diff for: src/seprocessor.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ SingleEndProcessor::~SingleEndProcessor() {
4141
delete mReadPool;
4242
mReadPool = NULL;
4343
}
44+
for(int t=0; t<mOptions->thread; t++){
45+
delete mInputLists[t];
46+
}
47+
delete[] mInputLists;
4448
}
4549

4650
void SingleEndProcessor::initOutput() {

Diff for: src/singleproducersingleconsumerlist.h

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class SingleProducerSingleConsumerList {
8383
blocks[recycled & blocksRingBufferSizeMask] = NULL;
8484
recycled++;
8585
}
86+
delete[] blocks;
87+
blocks = NULL;
8688
}
8789
inline size_t size() {
8890
return produced - consumed;

Diff for: src/threadconfig.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ void ThreadConfig::cleanup() {
4141
delete mRightInputList;
4242
mRightInputList = NULL;
4343
}
44+
if(mPreStats1) {
45+
delete mPreStats1;
46+
mPreStats1 = NULL;
47+
}
48+
if(mPostStats1) {
49+
delete mPostStats1;
50+
mPostStats1 = NULL;
51+
}
52+
if(mPreStats2) {
53+
delete mPreStats2;
54+
mPreStats2 = NULL;
55+
}
56+
if(mPostStats2) {
57+
delete mPostStats2;
58+
mPostStats2 = NULL;
59+
}
60+
if(mFilterResult) {
61+
delete mFilterResult;
62+
mFilterResult = NULL;
63+
}
4464
}
4565

4666

Diff for: src/writerthread.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ void WriterThread::input(int tid, string* data) {
5555

5656
void WriterThread::cleanup() {
5757
deleteWriter();
58+
for(int t=0; t<mOptions->thread; t++) {
59+
delete mBufferLists[t];
60+
}
61+
delete[] mBufferLists;
62+
mBufferLists = NULL;
5863
}
5964

6065
void WriterThread::deleteWriter() {

0 commit comments

Comments
 (0)