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



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;

or how about:

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

--
.tom






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