Re: [xml] How to treat an xmlBuffer's content to free later?
- From: Daniel Veillard <veillard redhat com>
- To: tgagne efinnet com
- Cc: libxml2 list <xml gnome org>
- Subject: Re: [xml] How to treat an xmlBuffer's content to free later?
- Date: Tue, 22 Jan 2002 03:55:43 -0500
On Mon, Jan 21, 2002 at 10:48:09PM -0500, Thomas Gagne wrote:
I need to return the content to PHP, which will want to free the memory I send
it. What is the best way to fashion a pointer to the buffer's contents, or a
copy of the contents, so that it appears to be a string that can be freed by
the caller?
Is it enough to "return xmlBufferContent(buf);"? Or should I instead:
string = calloc(xmlBufferLength(buf), 1);
memcpy(string, xmlBufferContent(buf), xmlBufferLength(buf));
xmlBufferFree(buf);
return string;
yes
or how about:
string = xmlStrdup(xmlBufferContent(buf));
xmlBufferFree(buf);
return string;
wrong, string would point to an unallocated piece of memory
I have updated xmlBufferFree()' doc to clarify it,
Daniel
--
Daniel Veillard | Red Hat Network https://rhn.redhat.com/
veillard redhat com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]