diff --git a/src/doctree.hh b/src/doctree.hh index d463255..fac5ea4 100644 --- a/src/doctree.hh +++ b/src/doctree.hh @@ -29,9 +29,9 @@ class DoctreeNode { ~DoctreeNode () { dFree ((void*) id); while (lastChild) { - DoctreeNode *n = lastChild; - lastChild = lastChild->sibling; - delete n; + std::unique_ptr< DoctreeNode > deleter; + deleter.reset( lastChild ); // It's a step toward RAII + lastChild = deleter->sibling; } } }; @@ -57,13 +57,13 @@ class Doctree { ~Doctree ()= default; DoctreeNode *push () { - DoctreeNode *dn = new DoctreeNode (); + auto dn= std::make_unique< DoctreeNode >(); dn->parent = topNode; dn->sibling = dn->parent->lastChild; - dn->parent->lastChild = dn; dn->num = num++; - topNode = dn; - return dn; + dn->parent->lastChild = dn.get(); + topNode = dn.get(); + return dn.release(); }; void pop () {