From 7452d320bee33d2214b080a131bc866ce3a047f4 Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Thu, 12 Jan 2006 21:22:03 +0000 Subject: [PATCH] Avoid creating new xml parser for each test file. This plugs a mem leak in the test case. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12329 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/backend/file/test/test-file-stuff.c | 48 ++++++++++++------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/backend/file/test/test-file-stuff.c b/src/backend/file/test/test-file-stuff.c index 2de4892ff2..8e69272eba 100644 --- a/src/backend/file/test/test-file-stuff.c +++ b/src/backend/file/test/test-file-stuff.c @@ -322,43 +322,21 @@ grab_file_doc(const char *filename) } 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)) - { - 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)) + if (!gnc_xml_parse_file(top_parser, filename, cb, node->children, book)) { failure_args("failure to parse file", __FILE__, __LINE__, "%s", filename); @@ -373,6 +351,21 @@ test_files_in_dir(int argc, char **argv, gxpf_callback cb, 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++) { @@ -380,6 +373,7 @@ test_files_in_dir(int argc, char **argv, gxpf_callback cb, 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 @@ test_files_in_dir(int argc, char **argv, gxpf_callback cb, #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); }