Fixed possibility of use-after-free

Using elem after node->LinkEndChild(elem) is not recommended, because the function takes control of the object pointed by elem and may also delete it. Added a unique_ptr<> to ensure it doesn't leak if an exception is raised inside the if-block.
Merge branch 'master' of https://github.com/polserver/polserver