Skip to content

Commit

Permalink
Fixed memory leak in isotope detection
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenemel committed Jun 13, 2019
1 parent a991595 commit 242f9a9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
49 changes: 27 additions & 22 deletions src/maven/background_peaks_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,37 +670,42 @@ void BackgroundPeakUpdate::pullIsotopes(PeakGroup* parentgroup) {

//cerr << "pullIsotopes: " << isotopeMass << " " << rtmin-w << " " << rtmin+w << " c=" << c << endl;

EIC* eic=NULL;
EIC* eic=nullptr;
for( int i=0; i<maxIsotopeScanDiff; i++ ) {
float window=i*avgScanTime;
eic = sample->getEIC(mzmin,mzmax,rtmin-window,rtmax+window,1);
if(!eic) continue;

eic->setSmootherType((EIC::SmootherType) eic_smoothingAlgorithm);
eic->getPeakPositions(eic_smoothingWindow);
if ( eic->peaks.size() == 0 ) continue;
if ( eic->peaks.size() > 1 ) break;
}
if (!eic) continue;

Peak* nearestPeak=NULL; float d=FLT_MAX;
for(int i=0; i < eic->peaks.size(); i++ ) {
Peak& x = eic->peaks[i];
float dist = abs(x.rt - rt);
if ( dist > maxIsotopeScanDiff*avgScanTime) continue;
if ( dist < d ) { d=dist; nearestPeak = &x; }
if (eic->peaks.size() > 1 ) break;

//clean up
delete(eic); eic=nullptr;
}

if (nearestPeak) {
if (isotopes.count(isotopeName)==0) {
PeakGroup g;
g.meanMz=isotopeMass;
g.tagString=isotopeName;
g.expectedAbundance=expectedAbundance;
g.isotopeC13count= x.C13;
isotopes[isotopeName] = g;
if (eic) {
Peak* nearestPeak=nullptr; float d=FLT_MAX;
for(int i=0; i < eic->peaks.size(); i++ ) {
Peak& x = eic->peaks[i];
float dist = abs(x.rt - rt);
if ( dist > maxIsotopeScanDiff*avgScanTime) continue;
if ( dist < d ) { d=dist; nearestPeak = &x; }
}

if (nearestPeak) {
if (isotopes.count(isotopeName)==0) {
PeakGroup g;
g.meanMz=isotopeMass;
g.tagString=isotopeName;
g.expectedAbundance=expectedAbundance;
g.isotopeC13count= x.C13;
isotopes[isotopeName] = g;
}
isotopes[isotopeName].addPeak(*nearestPeak);
}
isotopes[isotopeName].addPeak(*nearestPeak);
delete(eic);
}
delete(eic);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/maven_core

0 comments on commit 242f9a9

Please sign in to comment.