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/10408
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Reactor/SubzeroReactor.cpp b/src/Reactor/SubzeroReactor.cpp
index 0f65a37..aeed845 100644
--- a/src/Reactor/SubzeroReactor.cpp
+++ b/src/Reactor/SubzeroReactor.cpp
@@ -559,6 +559,8 @@
Nucleus::~Nucleus()
{
+ delete ::routine;
+
delete ::allocator;
delete ::function;
delete ::context;
@@ -604,7 +606,10 @@
objectWriter->setUndefinedSyms(::context->getConstantExternSyms());
objectWriter->writeNonUserSections();
- return ::routine;
+ Routine *handoffRoutine = ::routine;
+ ::routine = nullptr;
+
+ return handoffRoutine;
}
void Nucleus::optimize()
diff --git a/src/Renderer/LRUCache.hpp b/src/Renderer/LRUCache.hpp
index 77f9ab7..1a1a302 100644
--- a/src/Renderer/LRUCache.hpp
+++ b/src/Renderer/LRUCache.hpp
@@ -58,10 +58,10 @@
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 @@
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 @@
}
}
- 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 @@
fill = fill + 1 < size ? fill + 1 : size;
*ref[top] = key;
-
+
data->bind();
-
+
if(this->data[top])
{
this->data[top]->unbind();