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 <jh1302.park@samsung.com>
OpManager(Module *m = nullptr) { module(m); }
public:
+ ~OpManager();
+
+public:
template <typename T> T *create(void);
public:
#include <cassert>
#include <queue>
+#include <set>
using nncc::foundation::make_unique;
namespace coco
{
+OpManager::~OpManager()
+{
+ std::set<coco::Op *> 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
//