* [coco] Invoke detach from each Child class
The current implementation invokes 'detach' inside the destructor of Node.
Unfortunately, this may result in undefined behavior as detach may access the
internal of Child class (through leaving hook), but Child class is already
destructed.
With this commit, unlink on destruction is the responsibility of each
Child class.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
* Add a comment
public:
virtual ~Node()
{
- if (parent())
- {
- // Detach itself on destruction (if it belongs to a list).
- detach();
- }
+ // Each Child should unlink itself on destruction
+ //
+ // NOTE detach invokes "leaving" hook which may access the internal of each Child,
+ // so it is not safe to invoke detach here
+ assert(parent() == nullptr);
}
public:
Block(Block &&) = delete;
public:
+ ~Block()
+ {
+ if (parent())
+ {
+ detach();
+ }
+ }
+
+public:
InstrList *instr(void) { return &_instr; }
const InstrList *instr(void) const { return &_instr; }
Instr(Instr &&) = delete;
public:
- virtual ~Instr() = default;
+ virtual ~Instr()
+ {
+ if (parent())
+ {
+ // NOTE It is safe to invoke detach here (although "Instr" is not a final class)
+ // as "leaving" hook accesses only the internal of "Instr" class
+ detach();
+ }
+ }
public:
#define INSTR(Name) \
class Child final : public coco::DLinkedList<Child, Parent>::Node
{
- // DO NOTHING
+public:
+ ~Child()
+ {
+ if (parent())
+ {
+ detach();
+ }
+ }
};
} // namespace