Commit 619a8c5a by Nicolas Capens

Fix memory leak when aborting routine generation.

The blitter aborts generating a Reactor routine when a less common format is being used (causing fallback to statically compiled code). But the intermediate Reactor and Subzero structures were not being freed. It is fixed by deleting the global routine when the Function<> goes out of scope and it hasn't been acquired yet. Bug chromium:732691 Change-Id: I4904a467454e8e8d2ff0dbf64545823c9fd15802 Reviewed-on: https://swiftshader-review.googlesource.com/10408Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 9494572a
......@@ -559,6 +559,8 @@ namespace sw
Nucleus::~Nucleus()
{
delete ::routine;
delete ::allocator;
delete ::function;
delete ::context;
......@@ -604,7 +606,10 @@ namespace sw
objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
objectWriter->writeNonUserSections();
return ::routine;
Routine *handoffRoutine = ::routine;
::routine = nullptr;
return handoffRoutine;
}
void Nucleus::optimize()
......
......@@ -58,10 +58,10 @@ namespace sw
key = new Key[size];
ref = new Key*[size];
data = new Data*[size];
for(int i = 0; i < size; i++)
{
data[i] = 0;
data[i] = nullptr;
ref[i] = &key[i];
}
......@@ -71,22 +71,22 @@ namespace sw
LRUCache<Key, Data>::~LRUCache()
{
delete[] key;
key = 0;
key = nullptr;
delete[] ref;
ref = 0;
ref = nullptr;
for(int i = 0; i < size; i++)
{
if(data[i])
{
data[i]->unbind();
data[i] = 0;
data[i] = nullptr;
}
}
delete[] data;
data = 0;
data = nullptr;
}
template<class Key, class Data>
......@@ -118,9 +118,9 @@ namespace sw
}
}
return 0; // Not found
return nullptr; // Not found
}
template<class Key, class Data>
Data *LRUCache<Key, Data>::add(const Key &key, Data *data)
{
......@@ -128,9 +128,9 @@ namespace sw
fill = fill + 1 < size ? fill + 1 : size;
*ref[top] = key;
data->bind();
if(this->data[top])
{
this->data[top]->unbind();
......
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