On Sat, Jun 11, 2011 at 12:46:14PM +0100, Angus Comber wrote:
> 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"));
> }

  yes you would have to xmlFree(cur->content) assuming it's not NULL
before rewriting it

Daniel


-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
dan...@veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to