aboutsummaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorBart De Schuymer <deschuyb@b-virtual.org>2014-10-16 12:17:20 +0800
committerDaniel Veillard <veillard@redhat.com>2014-10-16 12:17:20 +0800
commit500c54ef326b62b8126e2d98d3a50f1a30dc5292 (patch)
treeda5610f54e6400b791f4cdaaac6f1a8d4b5d2cdb /parser.c
parent974db365de3a3d78a6cd7f5871f05e1432bab9b5 (diff)
downloadandroid_external_libxml2-500c54ef326b62b8126e2d98d3a50f1a30dc5292.tar.gz
android_external_libxml2-500c54ef326b62b8126e2d98d3a50f1a30dc5292.tar.bz2
android_external_libxml2-500c54ef326b62b8126e2d98d3a50f1a30dc5292.zip
fix memory leak xml header encoding field with XML_PARSE_IGNORE_ENC
When the xml parser encounters an xml encoding in an xml header while configured with option XML_PARSE_IGNORE_ENC, it fails to free memory allocated for storing the encoding. The patch below fixes this. How to reproduce: 1. Change doc/examples/parse4.c to add xmlCtxtUseOptions(ctxt, XML_PARSE_IGNORE_ENC); after the call to xmlCreatePushParserCtxt. 2. Rebuild 3. run the following command from the top libxml2 directory: LD_LIBRARY_PATH=.libs/ valgrind --leak-check=full ./doc/examples/.libs/parse4 ./test.xml , where test.xml contains following input: <?xml version="1.0" encoding="UTF-81" ?><hi/> valgrind will report: ==1964== 10 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==1964== at 0x4C272DB: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==1964== by 0x4E88497: xmlParseEncName (parser.c:10224) ==1964== by 0x4E888FE: xmlParseEncodingDecl (parser.c:10295) ==1964== by 0x4E89630: xmlParseXMLDecl (parser.c:10534) ==1964== by 0x4E8B737: xmlParseTryOrFinish (parser.c:11293) ==1964== by 0x4E8E775: xmlParseChunk (parser.c:12283) Signed-off-by: Bart De Schuymer <bart at amplidata com>
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/parser.c b/parser.c
index b9a37ab4..f51e8d25 100644
--- a/parser.c
+++ b/parser.c
@@ -10378,8 +10378,10 @@ xmlParseEncodingDecl(xmlParserCtxtPtr ctxt) {
/*
* Non standard parsing, allowing the user to ignore encoding
*/
- if (ctxt->options & XML_PARSE_IGNORE_ENC)
- return(encoding);
+ if (ctxt->options & XML_PARSE_IGNORE_ENC) {
+ xmlFree((xmlChar *) encoding);
+ return(NULL);
+ }
/*
* UTF-16 encoding stwich has already taken place at this stage,