[Gnucash-changes] r12329 - gnucash/trunk/src/backend/file/test - Avoid creating new xml parser for each test file.

Chris Shoemaker chris at cvs.gnucash.org
Thu Jan 12 16:22:04 EST 2006


Author: chris
Date: 2006-01-12 16:22:03 -0500 (Thu, 12 Jan 2006)
New Revision: 12329
Trac: http://svn.gnucash.org/trac/changeset/12329

Modified:
   gnucash/trunk/src/backend/file/test/test-file-stuff.c
Log:
Avoid creating new xml parser for each test file.
This plugs a mem leak in the test case.


Modified: gnucash/trunk/src/backend/file/test/test-file-stuff.c
===================================================================
--- gnucash/trunk/src/backend/file/test/test-file-stuff.c	2006-01-12 15:52:00 UTC (rev 12328)
+++ gnucash/trunk/src/backend/file/test/test-file-stuff.c	2006-01-12 21:22:03 UTC (rev 12329)
@@ -322,44 +322,22 @@
 }
     
 static void
-test_load_file(const char *filename, gxpf_callback cb,
-               sixtp *parser, const char *parser_tag,
+test_load_file(const char *filename, gxpf_callback cb, sixtp *top_parser, 
                QofBook *book)
 {
     xmlNodePtr node;
-    sixtp *main_parser;
-    sixtp *top_parser;
     
     node = grab_file_doc(filename);
 
-    if(!node)
+    if (!node)
     {
         failure_args("failure of libxml to parse file", __FILE__, __LINE__,
                      "%s", filename);
         return;
     }
 
-    top_parser = sixtp_new();
-    main_parser = sixtp_new();
-
-    if(!sixtp_add_some_sub_parsers(
-        top_parser, TRUE,
-        "gnc-v2", main_parser,
-        NULL, NULL))
+    if (!gnc_xml_parse_file(top_parser, filename, cb, node->children, book))
     {
-        return;
-    }
-    
-    if(!sixtp_add_some_sub_parsers(
-           main_parser, TRUE,
-           parser_tag, parser,
-           NULL, NULL))
-    {
-        return;
-    }
-
-    if(!gnc_xml_parse_file(top_parser, filename, cb, node->children, book))
-    {
         failure_args("failure to parse file", __FILE__, __LINE__,
                      "%s", filename);
     }
@@ -373,13 +351,29 @@
                   QofBook *book)
 {
     int count;
+    sixtp *main_parser;
+    sixtp *top_parser;
 
+
+    top_parser = sixtp_new();
+    main_parser = sixtp_new();
+
+    if (!sixtp_add_some_sub_parsers(top_parser, TRUE, "gnc-v2", main_parser,
+                                    NULL, NULL))
+        return;
+    
+    if (!sixtp_add_some_sub_parsers(main_parser, TRUE, parser_tag, parser,
+                                    NULL, NULL))
+        return;
+
+
     for(count = 1; count < argc; count++)
     {
         struct stat file_info;
         const char *to_open = argv[count];
         if(stat(to_open, &file_info) != 0)
         {
+            printf("cannot stat %s.\n", to_open);
             failure("unable to stat file");
         }
         else
@@ -389,8 +383,10 @@
 #if 0
                 printf( "testing load of file \"%s\":\n", argv[count] );
 #endif
-                test_load_file(to_open, cb, parser, parser_tag, book);
+                test_load_file(to_open, cb, top_parser, book);
             }
         }
     }
+    
+    sixtp_destroy(top_parser);
 }



More information about the gnucash-changes mailing list