Skip to content

Commit

Permalink
fix some possible memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sfchen committed Nov 7, 2024
1 parent 06d8679 commit 6a28a1e
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/peprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ PairEndProcessor::~PairEndProcessor() {
delete mRightReadPool;
mRightReadPool = NULL;
}
for(int t=0; t<mOptions->thread; t++){
delete mLeftInputLists[t];
delete mRightInputLists[t];
}
delete[] mLeftInputLists;
delete[] mRightInputLists;
}

void PairEndProcessor::initOutput() {
Expand Down
1 change: 0 additions & 1 deletion src/read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Read* Read::reverseComplement(){
string seq = Sequence::reverseComplement(mSeq);
string qual;
qual.assign(mQuality->rbegin(), mQuality->rend());
string* strand=new string("+");
return new Read(mName->c_str(), seq.c_str(), "+", qual.c_str());
}

Expand Down
11 changes: 9 additions & 2 deletions src/readpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ bool ReadPool::input(int tid, Read* data) {
}

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

void ReadPool::initBufferLists() {
Expand Down
4 changes: 4 additions & 0 deletions src/seprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ SingleEndProcessor::~SingleEndProcessor() {
delete mReadPool;
mReadPool = NULL;
}
for(int t=0; t<mOptions->thread; t++){
delete mInputLists[t];
}
delete[] mInputLists;
}

void SingleEndProcessor::initOutput() {
Expand Down
2 changes: 2 additions & 0 deletions src/singleproducersingleconsumerlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class SingleProducerSingleConsumerList {
blocks[recycled & blocksRingBufferSizeMask] = NULL;
recycled++;
}
delete[] blocks;
blocks = NULL;
}
inline size_t size() {
return produced - consumed;
Expand Down
20 changes: 20 additions & 0 deletions src/threadconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ void ThreadConfig::cleanup() {
delete mRightInputList;
mRightInputList = NULL;
}
if(mPreStats1) {
delete mPreStats1;
mPreStats1 = NULL;
}
if(mPostStats1) {
delete mPostStats1;
mPostStats1 = NULL;
}
if(mPreStats2) {
delete mPreStats2;
mPreStats2 = NULL;
}
if(mPostStats2) {
delete mPostStats2;
mPostStats2 = NULL;
}
if(mFilterResult) {
delete mFilterResult;
mFilterResult = NULL;
}
}


Expand Down
5 changes: 5 additions & 0 deletions src/writerthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ void WriterThread::input(int tid, string* data) {

void WriterThread::cleanup() {
deleteWriter();
for(int t=0; t<mOptions->thread; t++) {
delete mBufferLists[t];
}
delete[] mBufferLists;
mBufferLists = NULL;
}

void WriterThread::deleteWriter() {
Expand Down

0 comments on commit 6a28a1e

Please sign in to comment.