Fix a memory leak in TraceAnalyzer

A memory leak was fixed by replacing std::shared_ptr with std::weak_ptr
in phase.h and phase.cpp for the pointer to its transaction.
Not checking if the transaction is still valid is ok, because the
transaction outlives the phase.
This commit is contained in:
2021-06-30 16:25:38 +02:00
parent 0141bde845
commit 2a0c7ae771
2 changed files with 7 additions and 7 deletions

View File

@@ -129,22 +129,22 @@ QColor Phase::getColor(const TraceDrawingProperties &drawingProperties) const
break;
case ColorGrouping::Thread:
return ColorGenerator::getColor(static_cast<unsigned int>
(transaction->thread));
(transaction.lock()->thread));
break;
case ColorGrouping::Transaction:
default:
return ColorGenerator::getColor(transaction->id);
return ColorGenerator::getColor(transaction.lock()->id);
}
}
int Phase::getYVal(const TraceDrawingProperties &drawingProperties) const
{
if (getGranularity() == Granularity::Bankwise)
return drawingProperties.getYValOfBank(transaction->bank);
return drawingProperties.getYValOfBank(transaction.lock()->bank);
else if (getGranularity() == Granularity::Groupwise)
return drawingProperties.getYValOfBankGroup(transaction->rank, transaction->bank);
return drawingProperties.getYValOfBankGroup(transaction.lock()->rank, transaction.lock()->bank);
else // if (getGranularity() == Granularity::Rankwise)
return drawingProperties.getYValOfRank(transaction->rank);
return drawingProperties.getYValOfRank(transaction.lock()->rank);
}
Qt::BrushStyle Phase::getBrushStyle() const
@@ -206,5 +206,5 @@ bool Phase::isCollapsed(const TraceDrawingProperties &drawingProperties) const
if (dynamic_cast<const REQ *>(this) != nullptr || dynamic_cast<const RESP *>(this) != nullptr)
return false;
return drawingProperties.getRankCollapsedState(transaction->rank);
return drawingProperties.getRankCollapsedState(transaction.lock()->rank);
}

View File

@@ -80,7 +80,7 @@ protected:
ID id;
Timespan span;
traceTime clk;
std::shared_ptr<Transaction> transaction;
std::weak_ptr<Transaction> transaction;
std::vector<Timespan> spansOnCommandBus;
std::shared_ptr<Timespan> spanOnDataBus;
double hexagonHeight;