OSDN Git Service

Fix memory leak when aborting routine generation.
authorNicolas Capens <capn@google.com>
Wed, 5 Jul 2017 18:10:46 +0000 (14:10 -0400)
committerNicolas Capens <capn@google.com>
Wed, 5 Jul 2017 18:52:03 +0000 (18:52 +0000)
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>
src/Reactor/SubzeroReactor.cpp
src/Renderer/LRUCache.hpp

index 0f65a37..aeed845 100644 (file)
@@ -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()
index 77f9ab7..1a1a302 100644 (file)
@@ -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();