From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Thu, 6 Dec 2018 00:23:02 +0000 (+0900) Subject: [coco] Deallocate Op in OpManager properly (#2500) X-Git-Tag: nncc_backup~1187 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f6082af255a4aacdf80c302dd77e2a1d47ce253f;p=platform%2Fcore%2Fml%2Fnnfw.git [coco] Deallocate Op in OpManager properly (#2500) The current implementation of OpManager just deallocates all the Op in sequential order without considering their dependencies. However, this implementation may result in USE-AFTER-FREE errors. This commit guarantees that OpManager deallocates Op nodes from the root to leaves. Signed-off-by: Jonghyun Park --- diff --git a/contrib/coco/core/include/coco/IR/OpManager.h b/contrib/coco/core/include/coco/IR/OpManager.h index 95769f9..5f4f33c 100644 --- a/contrib/coco/core/include/coco/IR/OpManager.h +++ b/contrib/coco/core/include/coco/IR/OpManager.h @@ -37,6 +37,9 @@ public: OpManager(Module *m = nullptr) { module(m); } public: + ~OpManager(); + +public: template T *create(void); public: diff --git a/contrib/coco/core/src/IR/OpManager.cpp b/contrib/coco/core/src/IR/OpManager.cpp index ad20375..3911eb6 100644 --- a/contrib/coco/core/src/IR/OpManager.cpp +++ b/contrib/coco/core/src/IR/OpManager.cpp @@ -20,12 +20,35 @@ #include #include +#include using nncc::foundation::make_unique; namespace coco { +OpManager::~OpManager() +{ + std::set roots; + + for (uint32_t n = 0; n < size(); ++n) + { + auto op = at(n); + + if (op->up() != nullptr) + { + continue; + } + + roots.insert(op); + } + + for (const auto &op : roots) + { + destroy_all(op); + } +} + // // Each Op class SHOULD be default constructible //