Re: [xml] Do I need to free existing content before overwriting with a new string?
- From: Daniel Veillard <veillard redhat com>
- To: Angus Comber <iteloffice gmail com>
- Cc: libxml mailing list <xml gnome org>
- Subject: Re: [xml] Do I need to free existing content before overwriting with a new string?
- Date: Sun, 12 Jun 2011 09:08:38 +0800
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/
daniel veillard com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]