Memory leak and "Unimplemented block" on parse error using reader and schema
Validating the attached xml file (with a missing >
in the last tag) against the attached xsd schema causes this print:
Unimplemented block at /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:28703
Address sanitizer also detects a memory leak in this case, which seems to go away if I remove the following from the xsd:
<xs:unique name="UniqueName">
<xs:selector xpath=".//*"/>
<xs:field xpath="@Name"/>
</xs:unique>
Build master branch:
$ git clone https://gitlab.gnome.org/GNOME/libxml2.git
$ cd libxml2
$ git show
commit 3c4e4bb7264afeab0704df287343d4c77ca8f8a1 (HEAD -> master, origin/master, origin/HEAD)
...
$ cd ..
$ cmake -S libxml2 -B libxml2-build -DLIBXML2_WITH_ICONV=OFF -DLIBXML2_WITH_LZMA=OFF -DLIBXML2_WITH_PYTHON=OFF -DLIBXML2_WITH_ZLIB=OFF -DCMAKE_INSTALL_PREFIX=libxml2-install -DCMAKE_C_FLAGS="-m32 -g -fsanitize=address -fno-omit-frame-pointer" -DCMAKE_CXX_FLAGS="-m32 -g -fsanitize=address -fno-omit-frame-pointer" -DCMAKE_LINKER_FLAGS_DEBUG="-fsanitize=address"
$ cmake --build libxml2-build
Run xmllint using attached xml and xsd schema and enable --stream:
$ ./libxml2-build/xmllint leak-example.xml --schema leak-example.xsd --stream
Output:
Unimplemented block at /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:28703
leak-example.xml validates
leak-example.xml : failed to parse
=================================================================
==529015==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 40 byte(s) in 1 object(s) allocated from:
#0 0xf7aa5817 in __interceptor_malloc ../../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
#1 0xf781dbc8 in xmlSchemaIDCRegisterMatchers /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:23457
#2 0xf78298ea in xmlSchemaValidateElemDecl /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:25341
#3 0xf7834bc6 in xmlSchemaValidateElem /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:27179
#4 0xf7836b75 in xmlSchemaSAXHandleStartElementNs /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:27668
#5 0xf783d021 in startElementNsSplit /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:28786
#6 0xf761d76c in xmlParseStartTag2 /home/semawil3/tmp/libxml2-leak/libxml2/parser.c:9657
#7 0xf7632d35 in xmlParseTryOrFinish /home/semawil3/tmp/libxml2-leak/libxml2/parser.c:11449
#8 0xf763c735 in xmlParseChunk /home/semawil3/tmp/libxml2-leak/libxml2/parser.c:12342
#9 0xf775222a in xmlTextReaderPushData /home/semawil3/tmp/libxml2-leak/libxml2/xmlreader.c:825
#10 0xf7754d13 in xmlTextReaderRead /home/semawil3/tmp/libxml2-leak/libxml2/xmlreader.c:1244
#11 0x56612477 in streamFile /home/semawil3/tmp/libxml2-leak/libxml2/xmllint.c:1879
#12 0x5661ea32 in main /home/semawil3/tmp/libxml2-leak/libxml2/xmllint.c:3751
#13 0xf7315ee4 in __libc_start_main (/lib/i386-linux-gnu/libc.so.6+0x1aee4)
Indirect leak of 40 byte(s) in 1 object(s) allocated from:
#0 0xf7aa5817 in __interceptor_malloc ../../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
#1 0xf781a4c1 in xmlSchemaXPathProcessHistory /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:22975
#2 0xf782d602 in xmlSchemaVAttributesComplex /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:25956
#3 0xf783529b in xmlSchemaValidateElem /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:27228
#4 0xf7836b75 in xmlSchemaSAXHandleStartElementNs /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:27668
#5 0xf783d021 in startElementNsSplit /home/semawil3/tmp/libxml2-leak/libxml2/xmlschemas.c:28786
#6 0xf761d76c in xmlParseStartTag2 /home/semawil3/tmp/libxml2-leak/libxml2/parser.c:9657
#7 0xf7632d35 in xmlParseTryOrFinish /home/semawil3/tmp/libxml2-leak/libxml2/parser.c:11449
#8 0xf763c735 in xmlParseChunk /home/semawil3/tmp/libxml2-leak/libxml2/parser.c:12342
#9 0xf775222a in xmlTextReaderPushData /home/semawil3/tmp/libxml2-leak/libxml2/xmlreader.c:825
#10 0xf7754d13 in xmlTextReaderRead /home/semawil3/tmp/libxml2-leak/libxml2/xmlreader.c:1244
#11 0x56612477 in streamFile /home/semawil3/tmp/libxml2-leak/libxml2/xmllint.c:1879
#12 0x5661ea32 in main /home/semawil3/tmp/libxml2-leak/libxml2/xmllint.c:3751
#13 0xf7315ee4 in __libc_start_main (/lib/i386-linux-gnu/libc.so.6+0x1aee4)
SUMMARY: AddressSanitizer: 80 byte(s) leaked in 2 allocation(s).