[coco] Change object destruction order (#1508)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 17 Sep 2018 02:04:42 +0000 (11:04 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 17 Sep 2018 02:04:42 +0000 (11:04 +0900)
This commit changes the order of object destruction in coco::Module
implementation to allow each block to detach itself from the
corresponding BlockList.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/coco/core/src/IR/Module.cpp

index 876d838..d5c76e4 100644 (file)
@@ -74,9 +74,6 @@ public:
   std::unique_ptr<coco::PtrLink<coco::Block, coco::Module>> _block_link;
 
 public:
-  std::unique_ptr<coco::EntityManager> _entity;
-
-public:
   coco::EntityManager *entity(void) override { return _entity.get(); }
   const coco::EntityManager *entity(void) const override { return _entity.get(); }
 
@@ -100,6 +97,13 @@ public:
 public:
   coco::OutputList *output(void) override { return _output.get(); }
   const coco::OutputList *output(void) const override { return _output.get(); }
+
+public:
+  // WARN _entity SHOULD BE declared after _block in order to allow each Block(s) to detach itself.
+  //
+  // If not, Block is destructed after its corresponding BlockList is destructed, which results
+  // in invalid memory access during the update on BlockList (inside Block's destructor).
+  std::unique_ptr<coco::EntityManager> _entity;
 };
 
 } // namespace