From fc119e329069fae2ac7c25bc36ccb8847bac04ad Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sun, 30 Apr 2023 15:28:12 +0200 Subject: [PATCH] examples: Don't call xmlCleanupParser and xmlMemoryDump xmlCleanupParser is dangerous and shouldn't be called in most cases. Being part of the examples led many people to use it incorrectly. xmlMemoryDump is an obsolete way to test for memory leaks. --- doc/examples/Makefile.am | 18 ----- doc/examples/examples.xml | 136 +++++++++++++++----------------------- doc/examples/index.html | 106 +++++++++++++---------------- doc/examples/index.py | 2 - doc/examples/io1.c | 8 --- doc/examples/parse1.c | 8 --- doc/examples/parse2.c | 8 --- doc/examples/parse3.c | 8 --- doc/examples/parse4.c | 8 --- doc/examples/reader1.c | 8 --- doc/examples/reader2.c | 8 --- doc/examples/reader3.c | 9 --- doc/examples/reader4.c | 8 --- doc/examples/testWriter.c | 8 --- doc/examples/tree1.c | 6 -- doc/examples/tree2.c | 10 --- doc/examples/xpath1.c | 7 -- doc/examples/xpath2.c | 7 -- 18 files changed, 101 insertions(+), 272 deletions(-) diff --git a/doc/examples/Makefile.am b/doc/examples/Makefile.am index 75e138be8..e30c02b4e 100644 --- a/doc/examples/Makefile.am +++ b/doc/examples/Makefile.am @@ -22,7 +22,6 @@ uninstall-local: clean-local: test -f Makefile.am || rm -f test?.xml - rm -f .memdump EXTRA_DIST = \ examples.xml \ @@ -86,35 +85,18 @@ valgrind: check-local: @test -f Makefile.am || test -f test1.xml || $(LN_S) $(srcdir)/test?.xml . @(echo '## examples regression tests') - @(echo > .memdump) @$(CHECKER) ./io1 >/dev/null - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./io2 >/dev/null - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./parse1 test1.xml - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./parse2 test2.xml - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./parse3 - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./parse4 test3.xml - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./reader1 test2.xml >/dev/null - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./reader2 test2.xml >/dev/null - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./reader3 >/dev/null - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./reader4 test1.xml test2.xml test3.xml >/dev/null - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./testWriter - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./tree1 test2.xml >/dev/null - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./tree2 >/dev/null - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 - @$(CHECKER) ./xpath1 test3.xml '//child2' >/dev/null - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @$(CHECKER) ./xpath2 test3.xml '//discarded' discarded >/dev/null - @grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0 @rm -f *.tmp diff --git a/doc/examples/examples.xml b/doc/examples/examples.xml index 465ea8247..177e81599 100644 --- a/doc/examples/examples.xml +++ b/doc/examples/examples.xml @@ -15,11 +15,9 @@ - - @@ -62,10 +60,8 @@ - - @@ -84,12 +80,10 @@ - - @@ -108,10 +102,8 @@ - - @@ -129,12 +121,10 @@ - - @@ -152,9 +142,7 @@ - - @@ -250,35 +238,35 @@ <libxml/xmlwriter.h> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -338,22 +326,22 @@ <libxml/xpathInternals.h> - - - + + + - - - - - - - - - - - - + + + + + + + + + + + + @@ -371,17 +359,17 @@ <libxml/xpathInternals.h> - - + + - - - - - - - - + + + + + + + + @@ -429,14 +417,6 @@ - - - - - - - - @@ -506,14 +486,6 @@ - - - - - - - - diff --git a/doc/examples/index.html b/doc/examples/index.html index ff7b1cd38..b4d29f31c 100644 --- a/doc/examples/index.html +++ b/doc/examples/index.html @@ -87,8 +87,6 @@ install step or when installing the libxml2 development package:

  • line 134: Function xmlXIncludeProcess from xinclude.h
  • line 143: Function xmlDocDump from tree.h
  • line 149: Function xmlFreeDoc from tree.h
  • -
  • line 154: Function xmlCleanupParser from parser.h
  • -
  • line 158: Function xmlMemoryDump from xmlmemory.h
  • Usage:

    io1

    @@ -133,8 +131,6 @@ install step or when installing the libxml2 development package:

  • line 26: Function xmlReadFile from parser.h
  • line 31: Function xmlFreeDoc from tree.h
  • line 45: Macro LIBXML_TEST_VERSION from xmlversion.h
  • -
  • line 50: Function xmlCleanupParser from parser.h
  • -
  • line 54: Function xmlMemoryDump from xmlmemory.h
  • Usage:

    parse1 test1.xml

    @@ -159,8 +155,6 @@ install step or when installing the libxml2 development package:

  • line 44: Function xmlFreeDoc from tree.h
  • line 47: Function xmlFreeParserCtxt from parser.h
  • line 61: Macro LIBXML_TEST_VERSION from xmlversion.h
  • -
  • line 66: Function xmlCleanupParser from parser.h
  • -
  • line 70: Function xmlMemoryDump from xmlmemory.h
  • Usage:

    parse2 test2.xml

    @@ -182,8 +176,6 @@ install step or when installing the libxml2 development package:

  • line 33: Function xmlReadMemory from parser.h
  • line 38: Function xmlFreeDoc from tree.h
  • line 49: Macro LIBXML_TEST_VERSION from xmlversion.h
  • -
  • line 54: Function xmlCleanupParser from parser.h
  • -
  • line 58: Function xmlMemoryDump from xmlmemory.h
  • Usage:

    parse3

    @@ -208,8 +200,6 @@ install step or when installing the libxml2 development package:

  • line 94: Function xmlFreeParserCtxt from parser.h
  • line 103: Function xmlFreeDoc from tree.h
  • line 120: Macro LIBXML_TEST_VERSION from xmlversion.h
  • -
  • line 131: Function xmlCleanupParser from parser.h
  • -
  • line 135: Function xmlMemoryDump from xmlmemory.h
  • Usage:

    parse4 test3.xml

    @@ -281,18 +271,18 @@ install step or when installing the libxml2 development package:

    Uses:

    Usage:

    xpath1 <xml-file> <xpath-expr> [<known-ns-list>]

    @@ -317,15 +307,15 @@ install step or when installing the libxml2 development package:

    Uses:

    Usage:

    xpath2 <xml-file> <xpath-expr> <new-value>

    @@ -353,8 +343,6 @@ install step or when installing the libxml2 development package:

  • line 64: Function xmlTextReaderRead from xmlreader.h
  • line 69: Function xmlFreeTextReader from xmlreader.h
  • line 89: Macro LIBXML_TEST_VERSION from xmlversion.h
  • -
  • line 94: Function xmlCleanupParser from parser.h
  • -
  • line 98: Function xmlMemoryDump from xmlmemory.h
  • Usage:

    reader1 <filename>

    @@ -440,32 +428,32 @@ install step or when installing the libxml2 development package:

    Uses:

    Usage:

    testWriter

    diff --git a/doc/examples/index.py b/doc/examples/index.py index c422904f7..bceae8b99 100755 --- a/doc/examples/index.py +++ b/doc/examples/index.py @@ -262,10 +262,8 @@ clean-local: Makefile = Makefile + "tests: $(check_PROGRAMS)\n" Makefile = Makefile + "\t@test -f Makefile.am || test -f test1.xml || $(LN_S) $(srcdir)/test?.xml .\n" Makefile = Makefile + "\t@(echo '## examples regression tests')\n" - Makefile = Makefile + "\t@(echo > .memdump)\n" for test in tests: Makefile = Makefile + "\t@$(CHECKER) %s\n" % (test) - Makefile = Makefile + '\t@grep "MORY ALLO" .memdump | grep -v "MEMORY ALLOCATED : 0" ; exit 0\n' Makefile = Makefile + "\t@rm *.tmp\n" try: old = open("Makefile.am", "r").read() diff --git a/doc/examples/io1.c b/doc/examples/io1.c index 5c2b25d79..366c63cb9 100644 --- a/doc/examples/io1.c +++ b/doc/examples/io1.c @@ -148,14 +148,6 @@ int main(void) { */ xmlFreeDoc(doc); - /* - * Cleanup function for the XML library. - */ - xmlCleanupParser(); - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return(0); } #else diff --git a/doc/examples/parse1.c b/doc/examples/parse1.c index e3c9d3a67..01087d1ab 100644 --- a/doc/examples/parse1.c +++ b/doc/examples/parse1.c @@ -44,13 +44,5 @@ int main(int argc, char **argv) { example1Func(argv[1]); - /* - * Cleanup function for the XML library. - */ - xmlCleanupParser(); - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return(0); } diff --git a/doc/examples/parse2.c b/doc/examples/parse2.c index 4dcbfde9a..0732e1e5d 100644 --- a/doc/examples/parse2.c +++ b/doc/examples/parse2.c @@ -60,13 +60,5 @@ int main(int argc, char **argv) { exampleFunc(argv[1]); - /* - * Cleanup function for the XML library. - */ - xmlCleanupParser(); - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return(0); } diff --git a/doc/examples/parse3.c b/doc/examples/parse3.c index 076a786a2..15349dccd 100644 --- a/doc/examples/parse3.c +++ b/doc/examples/parse3.c @@ -48,13 +48,5 @@ int main(void) { example3Func(document, 6); - /* - * Cleanup function for the XML library. - */ - xmlCleanupParser(); - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return(0); } diff --git a/doc/examples/parse4.c b/doc/examples/parse4.c index ae8d332a9..eaeab40c9 100644 --- a/doc/examples/parse4.c +++ b/doc/examples/parse4.c @@ -125,14 +125,6 @@ int main(int argc, char **argv) { fprintf(stderr, "Failed to parse %s\n", argv[1]); } - /* - * Cleanup function for the XML library. - */ - xmlCleanupParser(); - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return(0); } #else /* ! LIBXML_PUSH_ENABLED */ diff --git a/doc/examples/reader1.c b/doc/examples/reader1.c index 103016865..eafb6e1d4 100644 --- a/doc/examples/reader1.c +++ b/doc/examples/reader1.c @@ -88,14 +88,6 @@ int main(int argc, char **argv) { streamFile(argv[1]); - /* - * Cleanup function for the XML library. - */ - xmlCleanupParser(); - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return(0); } diff --git a/doc/examples/reader2.c b/doc/examples/reader2.c index 9c2d2e6b3..d8d7f924b 100644 --- a/doc/examples/reader2.c +++ b/doc/examples/reader2.c @@ -103,14 +103,6 @@ int main(int argc, char **argv) { streamFile(argv[1]); - /* - * Cleanup function for the XML library. - */ - xmlCleanupParser(); - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return(0); } diff --git a/doc/examples/reader3.c b/doc/examples/reader3.c index f60829795..d6a43b1b5 100644 --- a/doc/examples/reader3.c +++ b/doc/examples/reader3.c @@ -100,15 +100,6 @@ int main(int argc, char **argv) { xmlFreeDoc(doc); } - - /* - * Cleanup function for the XML library. - */ - xmlCleanupParser(); - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return(0); } diff --git a/doc/examples/reader4.c b/doc/examples/reader4.c index f4277ec4f..3c0d1b97d 100644 --- a/doc/examples/reader4.c +++ b/doc/examples/reader4.c @@ -103,14 +103,6 @@ int main(int argc, char **argv) { */ xmlFreeTextReader(readerPtr); - /* - * Cleanup function for the XML library. - */ - xmlCleanupParser(); - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return(0); } diff --git a/doc/examples/testWriter.c b/doc/examples/testWriter.c index a77eec710..948cf16f4 100644 --- a/doc/examples/testWriter.c +++ b/doc/examples/testWriter.c @@ -48,14 +48,6 @@ main(void) /* next, the tree version */ testXmlwriterTree("writer4.tmp"); - /* - * Cleanup function for the XML library. - */ - xmlCleanupParser(); - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return 0; } diff --git a/doc/examples/tree1.c b/doc/examples/tree1.c index e8fc8d1b1..28fc1b70c 100644 --- a/doc/examples/tree1.c +++ b/doc/examples/tree1.c @@ -78,12 +78,6 @@ main(int argc, char **argv) /*free the document */ xmlFreeDoc(doc); - /* - *Free the global variables that may - *have been allocated by the parser. - */ - xmlCleanupParser(); - return 0; } #else diff --git a/doc/examples/tree2.c b/doc/examples/tree2.c index 83f29a0b5..78dcac142 100644 --- a/doc/examples/tree2.c +++ b/doc/examples/tree2.c @@ -97,16 +97,6 @@ main(int argc, char **argv) /*free the document */ xmlFreeDoc(doc); - /* - *Free the global variables that may - *have been allocated by the parser. - */ - xmlCleanupParser(); - - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return(0); } #else diff --git a/doc/examples/xpath1.c b/doc/examples/xpath1.c index af996e697..14efcbab9 100644 --- a/doc/examples/xpath1.c +++ b/doc/examples/xpath1.c @@ -45,13 +45,6 @@ main(int argc, char **argv) { return(-1); } - /* Shutdown libxml */ - xmlCleanupParser(); - - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return 0; } diff --git a/doc/examples/xpath2.c b/doc/examples/xpath2.c index a17a0256a..bf4e631d0 100644 --- a/doc/examples/xpath2.c +++ b/doc/examples/xpath2.c @@ -47,13 +47,6 @@ main(int argc, char **argv) { return(-1); } - /* Shutdown libxml */ - xmlCleanupParser(); - - /* - * this is to debug memory for regression tests - */ - xmlMemoryDump(); return 0; }