Re: [xml] How to treat an xmlBuffer's content to free later?

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));
     return string;


or how about:

         string = xmlStrdup(xmlBufferContent(buf));
         return string;

  wrong, string would point to an unallocated piece of memory
  I have updated xmlBufferFree()' doc to clarify it,


Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml Gnome XML XSLT toolkit | Rpmfind RPM search engine

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