Shouldn't the result of xmlEncodeEntitiesReentrant(NULL, root_url) be freed with av_free or xmlFree? xmlChar *tmp_str = NULL; tmp_str = xmlEncodeEntitiesReentrant(NULL, root_url); xmlNodeSetContent(node, tmp_str); xmlFree(tmp_str);