XSLT Extension Function Implementation

I am trying to create xslt extension function for libxslt (c++). My extension function takes a string as input, then this string parsed by xml parser, and function returns this parsed xml. I return value by this expression:

void fnParse(xmlXPathParserContextPtr ctx, int nargs)
{
    ...
    xmlXPathReturnNodeSet(ctx, xmlXPathNodeSetCreate(node));
}

But I have found that libxslt does not free node memory after use. It free xmlNodeSet, but not free the node which stored in this nodeset. Perhaps I missed something important. What is the correct way to return an XML node in extension function?