Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ReadPair's never being freed #515

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/fastqreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,12 @@ FastqReaderPair::~FastqReaderPair(){
}
}

ReadPair* FastqReaderPair::read(){
void FastqReaderPair::read(ReadPair* pair){
Read* l = mLeft->read();
Read* r = NULL;
if(mInterleaved)
r = mLeft->read();
else
r = mRight->read();
if(!l || !r){
return NULL;
} else {
return new ReadPair(l, r);
}
pair->setPair(l, r);
}
3 changes: 2 additions & 1 deletion src/fastqreader.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ class FastqReaderPair{
FastqReaderPair(FastqReader* left, FastqReader* right);
FastqReaderPair(string leftName, string rightName, bool hasQuality = true, bool phred64 = false, bool interleaved = false);
~FastqReaderPair();
ReadPair* read();
void read(ReadPair* pair);
bool eof();
public:
FastqReader* mLeft;
FastqReader* mRight;
Expand Down
15 changes: 7 additions & 8 deletions src/peprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ bool PairEndProcessor::processPairEnd(ReadPack* leftPack, ReadPack* rightPack, T
if(overlappedOut)
delete overlappedOut;

delete leftPack->data;
delete rightPack->data;
delete[] leftPack->data;
delete[] rightPack->data;
delete leftPack;
delete rightPack;

Expand Down Expand Up @@ -870,10 +870,11 @@ void PairEndProcessor::interleavedReaderTask()
FastqReaderPair reader(mOptions->in1, mOptions->in2, true, mOptions->phred64,true);
int count=0;
bool needToBreak = false;
ReadPair* pair = new ReadPair();
while(true){
ReadPair* pair = reader.read();
reader.read(pair);
// TODO: put needToBreak here is just a WAR for resolve some unidentified dead lock issue
if(!pair || needToBreak){
if(pair->eof() || needToBreak){
// the last pack
ReadPack* packLeft = new ReadPack;
ReadPack* packRight = new ReadPack;
Expand All @@ -890,10 +891,6 @@ void PairEndProcessor::interleavedReaderTask()

dataLeft = NULL;
dataRight = NULL;
if(pair) {
delete pair;
pair = NULL;
}
break;
}
dataLeft[count] = pair->mLeft;
Expand Down Expand Up @@ -962,6 +959,8 @@ void PairEndProcessor::interleavedReaderTask()
}
}

delete pair;

for(int t=0; t<mOptions->thread; t++) {
mLeftInputLists[t]->setProducerFinished();
mRightInputLists[t]->setProducerFinished();
Expand Down
18 changes: 14 additions & 4 deletions src/read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ bool Read::test(){
return idx == "GGTCCCGA";
}

ReadPair::ReadPair(Read* left, Read* right){
mLeft = left;
mRight = right;
ReadPair::ReadPair(){
mLeft = NULL;
mRight = NULL;
}

ReadPair::~ReadPair(){
Expand All @@ -213,6 +213,15 @@ ReadPair::~ReadPair(){
}
}

void ReadPair::setPair(Read* left, Read* right){
mLeft = left;
mRight = right;
}

bool ReadPair::eof(){
return mLeft == NULL || mRight == NULL;
}

Read* ReadPair::fastMerge(){
Read* rcRight = mRight->reverseComplement();
int len1 = mLeft->length();
Expand Down Expand Up @@ -297,7 +306,8 @@ bool ReadPair::test(){
new string("+"),
new string("AAAAA6EEEEE/EEEEEEEEEEE#EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAEEEAEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"));

ReadPair pair(left, right);
ReadPair pair;
pair.setPair(left, right);
Read* merged = pair.fastMerge();
if(merged == NULL)
return false;
Expand Down
4 changes: 3 additions & 1 deletion src/read.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ class Read{

class ReadPair{
public:
ReadPair(Read* left, Read* right);
ReadPair();
~ReadPair();
void setPair(Read* left, Read* right);
bool eof();

// merge a pair, without consideration of seq error caused false INDEL
Read* fastMerge();
Expand Down