]> granicus.if.org Git - libexpat/commitdiff
Make test_alloc_parse_xdecl() robust vs allocation pattern changes
authorRhodri James <rhodri@kynesim.co.uk>
Wed, 26 Jul 2017 17:29:06 +0000 (18:29 +0100)
committerRhodri James <rhodri@kynesim.co.uk>
Wed, 26 Jul 2017 17:56:37 +0000 (18:56 +0100)
expat/tests/runtests.c

index 59a426fa7e898ce325905fcf5f75d110e9f08b66..93aae88244cb3a3ff1be37e107cf3d62b4465312 100644 (file)
@@ -7846,25 +7846,21 @@ START_TEST(test_alloc_parse_xdecl)
         "<?xml version='1.0' encoding='utf-8'?>\n"
         "<doc>Hello, world</doc>";
     int i;
-    int repeat = 0;
-#define MAX_ALLOC_COUNT 10
+#define MAX_ALLOC_COUNT 15
 
     for (i = 0; i < MAX_ALLOC_COUNT; i++) {
-        /* Repeat some (most) counts to defeat cached allocations */
-        if (i == 2 && repeat != 1) {
-            i--;
-            repeat++;
-        }
-        else if (i == 3) {
-            i -= 2;
-            repeat++;
-        }
         allocation_count = i;
         XML_SetXmlDeclHandler(parser, dummy_xdecl_handler);
         if (_XML_Parse_SINGLE_BYTES(parser, text, strlen(text),
                                     XML_TRUE) != XML_STATUS_ERROR)
             break;
-        XML_ParserReset(parser, NULL);
+        /* Resetting the parser is insufficient, because some memory
+         * allocations are cached within the parser.  Instead we use
+         * the teardown and setup routines to ensure that we have the
+         * right sort of parser back in our hands.
+         */
+        alloc_teardown();
+        alloc_setup();
     }
     if (i == 0)
         fail("Parse succeeded despite failing allocator");