swr: [rasterizer archrast] fix double free issue
authorTim Rowley <timothy.o.rowley@intel.com>
Fri, 28 Oct 2016 22:21:01 +0000 (17:21 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Mon, 14 Nov 2016 15:02:11 +0000 (09:02 -0600)
Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/archrast/archrast.cpp
src/gallium/drivers/swr/rasterizer/archrast/archrast.h
src/gallium/drivers/swr/rasterizer/archrast/eventmanager.h
src/gallium/drivers/swr/rasterizer/core/api.cpp
src/gallium/drivers/swr/rasterizer/core/context.h
src/gallium/drivers/swr/rasterizer/scripts/templates/ar_event_cpp.template
src/gallium/drivers/swr/rasterizer/scripts/templates/ar_event_h.template
src/gallium/drivers/swr/rasterizer/scripts/templates/ar_eventhandler_h.template
src/gallium/drivers/swr/rasterizer/scripts/templates/ar_eventhandlerfile_h.template

index c29bb884588f31bc02860da7379be71bdc5cccae..574098d80a8880e6a753cc518a93a74b167b52ae 100644 (file)
@@ -43,8 +43,8 @@ namespace ArchRast
         EventHandlerStatsFile(uint32_t id) : EventHandlerFile(id) {}
 
         // These are events that we're not interested in saving in stats event files.
-        virtual void handle(Start& event) {}
-        virtual void handle(End& event) {}
+        virtual void Handle(Start& event) {}
+        virtual void Handle(End& event) {}
     };
 
     static EventManager* FromHandle(HANDLE hThreadContext)
@@ -64,7 +64,7 @@ namespace ArchRast
 
         if (pManager && pHandler)
         {
-            pManager->attach(pHandler);
+            pManager->Attach(pHandler);
 
             return pManager;
         }
@@ -82,11 +82,11 @@ namespace ArchRast
     }
 
     // Dispatch event for this thread.
-    void dispatch(HANDLE hThreadContext, Event& event)
+    void Dispatch(HANDLE hThreadContext, Event& event)
     {
         EventManager* pManager = FromHandle(hThreadContext);
         SWR_ASSERT(pManager != nullptr);
 
-        pManager->dispatch(event);
+        pManager->Dispatch(event);
     }
 }
index bdb3afbed99aae09fe806c175403064300a518ae..e6376f208fe8c259bba0b02d7238d86079149ca4 100644 (file)
@@ -36,6 +36,6 @@ namespace ArchRast
     void DestroyThreadContext(HANDLE hThreadContext);
 
     // Dispatch event for this thread.
-    void dispatch(HANDLE hThreadContext, Event& event);
+    void Dispatch(HANDLE hThreadContext, Event& event);
 };
 
index d162ca8fe57740ac357045cfae7844f7284eed69..78ba8f3e2d746377521f4c22a3a5a6be8f07ff73 100644 (file)
@@ -43,24 +43,36 @@ namespace ArchRast
     class EventManager
     {
     public:
-        void attach(EventHandler* pHandler)
+        EventManager() {}
+
+        ~EventManager()
+        {
+            // Event manager owns destroying handler objects once attached.
+            ///@note See comment for Detach.
+            for (auto pHandler : mHandlers)
+            {
+                delete pHandler;
+            }
+        }
+
+        void Attach(EventHandler* pHandler)
         {
             mHandlers.push_back(pHandler);
         }
 
-        void dispatch(Event& event)
+        void Dispatch(Event& event)
         {
             ///@todo Add event filter check here.
 
             for (auto pHandler : mHandlers)
             {
-                event.accept(pHandler);
+                event.Accept(pHandler);
             }
         }
     private:
 
         // Handlers stay registered for life
-        void detach(EventHandler* pHandler) { SWR_ASSERT(0); }
+        void Detach(EventHandler* pHandler) { SWR_ASSERT(0); }
 
         std::vector<EventHandler*> mHandlers;
     };
index e8e1fdd48415c87195c6437104e64dba7b10d3e5..542eccda95e685b688b6b331e765f58a04683085 100644 (file)
@@ -394,7 +394,6 @@ void SwrDestroyContext(HANDLE hContext)
     }
 
     delete[] pContext->ppScratch;
-    delete[] pContext->pArContext;
     delete[] pContext->pStats;
 
     delete(pContext->pHotTileMgr);
index 23685b42bb2ff11df64b35357077af2a83a3e686..e7c462da8b9f419090c929344762d633251670f8 100644 (file)
@@ -523,9 +523,9 @@ struct SWR_CONTEXT
 #define AR_API_CTX     pContext->pArContext[pContext->NumWorkerThreads]
 
 #ifdef KNOB_ENABLE_AR
-    #define _AR_BEGIN(ctx, type, id)    ArchRast::dispatch(ctx, ArchRast::Start(ArchRast::type, id))
-    #define _AR_END(ctx, type, count)   ArchRast::dispatch(ctx, ArchRast::End(ArchRast::type, count))
-    #define _AR_EVENT(ctx, event)       ArchRast::dispatch(ctx, ArchRast::event)
+    #define _AR_BEGIN(ctx, type, id)    ArchRast::Dispatch(ctx, ArchRast::Start(ArchRast::type, id))
+    #define _AR_END(ctx, type, count)   ArchRast::Dispatch(ctx, ArchRast::End(ArchRast::type, count))
+    #define _AR_EVENT(ctx, event)       ArchRast::Dispatch(ctx, ArchRast::event)
 #else
     #ifdef KNOB_ENABLE_RDTSC
         #define _AR_BEGIN(ctx, type, id) (void)ctx; RDTSC_START(type)
index d033d93e7344a3ff0c666aca4a6690b5d30e7898..4b3dcd57dbc31a31fedb660c06d88dc6f080064b 100644 (file)
@@ -34,8 +34,8 @@
 using namespace ArchRast;
 % for name in protos['event_names']:
 
-void ${name}::accept(EventHandler* pHandler)
+void ${name}::Accept(EventHandler* pHandler)
 {
-    pHandler->handle(*this);
+    pHandler->Handle(*this);
 }
 % endfor
index b0e679613043f8cf57b0034c75ce4ef0fc15ab58..68926ea805351c2ed2d63d492f9a04c64e36aaca 100644 (file)
@@ -51,7 +51,10 @@ namespace ArchRast
     //////////////////////////////////////////////////////////////////////////
     struct Event
     {
-        virtual void accept(EventHandler* pHandler) = 0;
+        Event() {}
+        virtual ~Event() {}
+
+        virtual void Accept(EventHandler* pHandler) = 0;
     };
 % for name in protos['event_names']:
 
@@ -96,7 +99,7 @@ namespace ArchRast
         % endfor
         }
 
-        virtual void accept(EventHandler* pHandler);
+        virtual void Accept(EventHandler* pHandler);
     };
 % endfor
 }
\ No newline at end of file
index 53e5a191b0bf3fb37ace1e54fe8fae1095ab3dcb..95c54426b509ea75e5b5547c1a3a869f6157f717 100644 (file)
@@ -39,8 +39,11 @@ namespace ArchRast
     class EventHandler
     {
     public:
+        EventHandler() {}
+        virtual ~EventHandler() {}
+
 % for name in protos['event_names']:
-        virtual void handle(${name}& event) {}
+        virtual void Handle(${name}& event) {}
 % endfor
     };
 }
index 5310bf55b3464342582a7ac2f378d1bd2d96f356..0a651a4e4a57f01719b91ae6fda45e8244f23924 100644 (file)
@@ -69,12 +69,12 @@ namespace ArchRast
 #endif
         }
 
-        ~EventHandlerFile()
+        virtual ~EventHandlerFile()
         {
             if (mFile.is_open()) mFile.close();
         }
 
-        void write(uint32_t eventId, const char* pBlock, uint32_t size)
+        void Write(uint32_t eventId, const char* pBlock, uint32_t size)
         {
             if (!mFile.is_open())
             {
@@ -86,12 +86,12 @@ namespace ArchRast
         }
 
 % for name in protos['event_names']:
-        virtual void handle(${name}& event)
+        virtual void Handle(${name}& event)
         {
 % if protos['events'][name]['num_fields'] == 0:
-            write(${protos['events'][name]['event_id']}, (char*)&event.data, 0);
+            Write(${protos['events'][name]['event_id']}, (char*)&event.data, 0);
 % else:
-            write(${protos['events'][name]['event_id']}, (char*)&event.data, sizeof(event.data));
+            Write(${protos['events'][name]['event_id']}, (char*)&event.data, sizeof(event.data));
 %endif
         }
 % endfor