Re: [xml] How to properly free a string allocated by xmlCharStrdup

Hi Nikolay,

On Thu, 26 Dec 2013 14:58:27 +0400
Nikolay Sivov <bunglehead gmail com> wrote:

On 12/26/2013 14:19, Shlomi Fish wrote:
Hi all,

happy holidays and a happy new (civil) year.

I'm the maintainer of XML::LibXSLT which are the CPAN bindings for libxslt.
Now, someone reported that the clang compiler emits some warnings, and part
of the problem was that I passed "1.0" to xmlNewDoc instead of its
equivalent "xmlChar *". So I did:

xmlChar * xml_ver = NULL;
xml_ver = xmlCharStrdup("1.0");

// At the function FINISH:
free( xml_ver );

Use xmlFree(). But for this particular case you don't need to allocate 
anything, just do xmlNewDoc(NULL).

Thanks! Hopefully it will work well. I credited you in the "Changes" file.

How can I properly free a string allocated by xmlCharStrdup? The
documentation is lacking on details (and, if you ask me, should be made
more explicit.).
You got all the code, for that case it's pretty simple.

Well, the fact is that I got it wrong. And twice. Also see what Joel on
Software wrote about fixing every problem two ways here:

Just for reference I refer to which says it is «a
strdup for char's to xmlChar's» and does not tell one how to free it (in fact
the string «xmlFree» does not appear anywhere on the page), which prompted me
to ask the question after getting a segmentation fault for that on Windows.


        Shlomi Fish

Shlomi Fish
Freecell Solver -

    — Bart Simpson on chalkboard in episode AABF17

Please reply to list if it's a mailing list post - .

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