[xml] Do I need to free existing content before overwriting with a new string?



Hello

I need to update the value of a particular key.  Using the libxml tutorial Appendix E as a starting point I changed parsestory as below to update the contents of the node with key=keyword.

Will this code leak memory?  Do I need to free the existing contents before overwriting? Here is code:


void parseStory (xmlDocPtr doc, xmlNodePtr cur, char *keyword) {
cur = cur->xmlChildrenNode;
while (cur != NULL) {
if ((!xmlStrcmp(cur->name, (const xmlChar *)"keyword"))){
            cur = cur->children;
            cur->content = xmlStrndup((const xmlChar *)"mynewvalue", strlen("mynewvalue"));
}
 
cur = cur->next;
}

    return;
}

Angus


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]