[xml] How to properly free a string allocated by xmlCharStrdup
- From: Shlomi Fish <shlomif shlomifish org>
- To: xml gnome org
- Subject: [xml] How to properly free a string allocated by xmlCharStrdup
- Date: Thu, 26 Dec 2013 12:19:00 +0200
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");
xmlNewDoc(xml_ver)
// At the function FINISH:
free( xml_ver );
However, now it was reported that the Win32 tests generate a segfault:
https://rt.cpan.org/Ticket/Display.html?id=91652
So I tried to replace free() by xmlMemFree() but now I'm getting errors upon
"make test" on Linux:
[QUOTE SHELL]
shlomif[XML-LibXML]:$xslt_trunk$ hg di
diff -r 0290d4243e9b LibXSLT.xs
--- a/LibXSLT.xs Sun Dec 22 18:23:22 2013 +0200
+++ b/LibXSLT.xs Thu Dec 26 12:15:35 2013 +0200
@@ -249,7 +249,7 @@
XPUSHs(perl_function);
- xml_ver = xmlCharStrdup("1.0");
+ xml_ver = xmlCharStrdup("1.0");
/* clone all of the arguments into a new owning document */
owner_doc = x_PmmNodeToSv(INT2PTR(xmlNodePtr,xmlNewDoc(xml_ver)), NULL);
XPUSHs( sv_2mortal(owner_doc) );
@@ -428,11 +428,11 @@
ret = (xmlXPathObjectPtr)xmlXPathNewCString(SvPV(perl_result, len));
FINISH:
- free( xml_ver );
+ xmlMemFree( xml_ver );
valuePush(ctxt, ret);
PUTBACK;
FREETMPS;
- LEAVE;
+ LEAVE;
}
/*
shlomif[XML-LibXML]:$xslt_trunk$ perl Mak
Makefile Makefile.old Makefile.PL Makefile.PL~
shlomif[XML-LibXML]:$xslt_trunk$ perl Makefile.PL
running xslt-config... ok
looking for -lxslt... yes
looking for -lexslt... yes
running pkg-config libexslt... ok
Warning (mostly harmless): No library found for -ldb
Generating a GNU-style Makefile
Writing Makefile for XML::LibXSLT
Writing MYMETA.yml and MYMETA.json
shlomif[XML-LibXML]:$xslt_trunk$ make
Skip blib/lib/XML/LibXSLT.pm (unchanged)
gcc -c -I/usr/include/libxml2 -I/usr/include/libxml2 -D_REENTRANT
-D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -g -pipe -Wformat
-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector
--param=ssp-buffer-size=4 -fPIC -Wl,--as-needed -Wl,-z,relro -Wl,-O1
-Wl,--build-id -Wl,--enable-new-dtags -pthread -DVERSION=\"1.83\"
-DXS_VERSION=\"1.83\" -fPIC
"-I/usr/lib/perl5/5.18.1/x86_64-linux-thread-multi/CORE" -DHAVE_BLANK
-DHAVE_BLANK -DHAVE_EXSLT LibXSLT.c gcc -c -I/usr/include/libxml2
-I/usr/include/libxml2 -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe
-fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -O2 -g -pipe -Wformat -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -fPIC
-Wl,--as-needed -Wl,-z,relro -Wl,-O1 -Wl,--build-id -Wl,--enable-new-dtags
-pthread -DVERSION=\"1.83\" -DXS_VERSION=\"1.83\" -fPIC
"-I/usr/lib/perl5/5.18.1/x86_64-linux-thread-multi/CORE" -DHAVE_BLANK
-DHAVE_BLANK -DHAVE_EXSLT perl-libxml-mm.c Running Mkbootstrap for XML::LibXSLT
() chmod 644 LibXSLT.bs rm -f blib/arch/auto/XML/LibXSLT/LibXSLT.so
LD_RUN_PATH="/usr/lib64" gcc -shared -O2 -g -pipe -Wformat
-Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector
--param=ssp-buffer-size=4 -fPIC -Wl,--as-needed -Wl,-z,relro -Wl,-O1
-Wl,--build-id -Wl,--enable-new-dtags -pthread -L/usr/local/lib64 LibXSLT.o
perl-libxml-mm.o -o blib/arch/auto/XML/LibXSLT/LibXSLT.so \ -L/usr/lib64
-lxslt -lxml2 -lz -ldl -lm -lexslt -ldl -lgcrypt -lgpg-error -lnsl -lgdbm -ldl
-lm -lcrypt -lutil -lpthread -lc -lgdbm_compat \ chmod 755
blib/arch/auto/XML/LibXSLT/LibXSLT.so cp LibXSLT.bs
blib/arch/auto/XML/LibXSLT/LibXSLT.bs chmod 644
blib/arch/auto/XML/LibXSLT/LibXSLT.bs Manifying blib/man3/XML::LibXSLT.3pm
shlomif[XML-LibXML]:$xslt_trunk$ make test
PERL_DL_NONLAZY=1 /usr/bin/perl5.18.1 "-MExtUtils::Command::MM"
"-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0,
'blib/lib', 'blib/arch')" t/*.t t/01basic.t ...... 1/4
Compiled against: libxslt 10128, libxml2 20901
Running: libxslt 10128, libxml2 20901
Compiled with EXSLT: yes
t/01basic.t ...... ok
t/02dromeds.t .... ok
t/03input.t ...... ok
t/04params.t ..... ok
t/05quick.t ...... ok
t/06entities.t ... ok
t/06output.t ..... ok
t/07blankdoc.t ... ok
t/08literal.t .... ok
t/09exslt.t ...... ok
t/10functions.t .. 1/38 Memory tag error occurs :1d89a78
bye
xmlMemFree(1D89AA0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d898b8
bye
xmlMemFree(1D898E0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d89ce8
bye
xmlMemFree(1D89D10) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d89f28
bye
xmlMemFree(1D89F50) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d8a6e8
bye
xmlMemFree(1D8A710) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d8a278
bye
xmlMemFree(1D8A2A0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :16c0af8
bye
xmlMemFree(16C0B20) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d8a1b8
bye
xmlMemFree(1D8A1E0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d84be8
bye
xmlMemFree(1D84C10) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :16c1298
bye
xmlMemFree(16C12C0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d8d758
bye
xmlMemFree(1D8D780) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d83278
bye
xmlMemFree(1D832A0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :16c56d8
bye
xmlMemFree(16C5700) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x1da6d18
bye
xmlMemFree(1DA6D40) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x1da7fd8
bye
xmlMemFree(1DA8000) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x1da82d8
bye
xmlMemFree(1DA8300) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d99db8
bye
xmlMemFree(1D99DE0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d99df8
bye
xmlMemFree(1D99E20) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1d99dd8
bye
xmlMemFree(1D99E00) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1dbaac8
bye
xmlMemFree(1DBAAF0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1dba248
bye
xmlMemFree(1DBA270) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1dbb628
bye
xmlMemFree(1DBB650) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1dbbb08
bye
xmlMemFree(1DBBB30) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1dbaae8
bye
xmlMemFree(1DBAB10) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1dbbba8
bye
xmlMemFree(1DBBBD0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :1dbc048
bye
xmlMemFree(1DBC070) error
xmlMallocBreakpoint reached on block 0
t/10functions.t .. ok
t/11utf8.t ....... ok
t/12import.t ..... ok
t/13error.t ...... ok
t/14security.t ... ok
t/15misc.t ....... ok
t/rt71345_a.t .... Memory tag error occurs :1886078
bye
xmlMemFree(18860A0) error
xmlMallocBreakpoint reached on block 0
t/rt71345_a.t .... ok
t/rt71345_b.t .... Memory tag error occurs :ef3ee8
bye
xmlMemFree(EF3F10) error
xmlMallocBreakpoint reached on block 0
t/rt71345_b.t .... ok
All tests successful.
Files=18, Tests=241, 2 wallclock secs ( 0.09 usr 0.02 sys + 0.98 cusr 0.11
csys = 1.20 CPU) Result: PASS
shlomif[XML-LibXML]:$xslt_trunk$
[ / QUOTE SHELL]
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.).
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman
Vizzini: He didn’t fall?! Inconceivable!
Inigo Montoya: You keep using that word. I do not think it means what you
think it means.
— http://en.wikiquote.org/wiki/The_Princess_Bride_%28film%29
Please reply to list if it's a mailing list post - http://shlom.in/reply .
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]