Commit 614a4d47 by Antonio Maiorano

Fix memory leak in rr::Optimizer

Leak was introduced in 5ba2a5b9. There are calls to setUses(operand, nullptr) in the algorithm, that, with the latest changes, would simply replace the existing allocated Uses object with a new one. Fix it so that setUses(operand, nullptr) deletes an existing Uses object on the Operand before allocating and assigning a new one. Bug: b/145754674 Change-Id: Ie1438378595401619831a2da81d4d0d54a606f80 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/40628Reviewed-by: 's avatarBen Clayton <bclayton@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
parent 89e30f0c
...@@ -106,9 +106,8 @@ void Optimizer::run(Ice::Cfg *function) ...@@ -106,9 +106,8 @@ void Optimizer::run(Ice::Cfg *function)
for(auto operand : operandsWithUses) for(auto operand : operandsWithUses)
{ {
auto uses = reinterpret_cast<Uses *>(operand->getExternalData()); // Deletes the Uses instance on the operand
delete uses; setUses(operand, nullptr);
operand->setExternalData(nullptr);
} }
operandsWithUses.clear(); operandsWithUses.clear();
} }
...@@ -722,6 +721,11 @@ Optimizer::Uses *Optimizer::getUses(Ice::Operand *operand) ...@@ -722,6 +721,11 @@ Optimizer::Uses *Optimizer::getUses(Ice::Operand *operand)
void Optimizer::setUses(Ice::Operand *operand, Optimizer::Uses *uses) void Optimizer::setUses(Ice::Operand *operand, Optimizer::Uses *uses)
{ {
if(auto *oldUses = reinterpret_cast<Optimizer::Uses *>(operand->Ice::Operand::getExternalData()))
{
delete oldUses;
}
operand->Ice::Operand::setExternalData(uses); operand->Ice::Operand::setExternalData(uses);
} }
...@@ -837,4 +841,4 @@ void optimize(Ice::Cfg *function) ...@@ -837,4 +841,4 @@ void optimize(Ice::Cfg *function)
optimizer.run(function); optimizer.run(function);
} }
} // namespace rr } // namespace rr
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment