diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-01-08 19:50:58 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-01-08 19:50:58 +0000 |
commit | 9a0e5a66822c6f9629a3b7bc2ff25b7098a926ad (patch) | |
tree | d8f5961c62418aa6d8096c6cf81fe190eef6e1f7 /examples | |
parent | 5a8784817cc0ff505a502d20e6eb6975ef281d15 (diff) | |
download | libhubbub-9a0e5a66822c6f9629a3b7bc2ff25b7098a926ad.tar.gz libhubbub-9a0e5a66822c6f9629a3b7bc2ff25b7098a926ad.tar.bz2 |
Squash memory leak.
Actually bother to clean up if we got errors, rather than just asserting.
svn path=/trunk/hubbub/; revision=5995
Diffstat (limited to 'examples')
-rw-r--r-- | examples/libxml.c | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/examples/libxml.c b/examples/libxml.c index 0f31410..6580151 100644 --- a/examples/libxml.c +++ b/examples/libxml.c @@ -170,6 +170,7 @@ int main(int argc, char **argv) */ input = fopen(argv[2], "r"); if (input == NULL) { + hubbub_finalise(myrealloc, NULL); fprintf(stderr, "Failed opening %s\n", argv[2]); return 1; } @@ -181,6 +182,7 @@ int main(int argc, char **argv) buf = malloc(len); if (buf == NULL) { fclose(input); + hubbub_finalise(myrealloc, NULL); fprintf(stderr, "No memory for buf\n"); return 1; } @@ -189,7 +191,13 @@ int main(int argc, char **argv) /* Create our parsing context */ error = create_context(NULL, &c); - assert(error == OK); + if (error != OK) { + free(buf); + fclose(input); + hubbub_finalise(myrealloc, NULL); + fprintf(stderr, "Failed creating parsing context\n"); + return 1; + } /* Attempt to parse the document */ error = parse_chunk(c, buf, len); @@ -207,8 +215,15 @@ int main(int argc, char **argv) */ hubbub_parser *temp; - assert(hubbub_parser_create(c->encoding, true, myrealloc, NULL, - &temp) == HUBBUB_OK); + if (hubbub_parser_create(c->encoding, true, myrealloc, NULL, + &temp) != HUBBUB_OK) { + destroy_context(c); + free(buf); + fclose(input); + hubbub_finalise(myrealloc, NULL); + fprintf(stderr, "Failed recreating parser\n"); + return 1; + } hubbub_parser_destroy(c->parser); c->parser = temp; @@ -216,11 +231,30 @@ int main(int argc, char **argv) /* Retry the parse */ error = parse_chunk(c, buf, len); } - assert(error == OK); + + if (error != OK) { + destroy_context(c); + free(buf); + fclose(input); + hubbub_finalise(myrealloc, NULL); + fprintf(stderr, "Failed parsing document\n"); + return 1; + } + /* Tell hubbub that we've finished */ error = parse_completed(c); - assert(error == OK); + if (error != OK) { + destroy_context(c); + free(buf); + fclose(input); + hubbub_finalise(myrealloc, NULL); + fprintf(stderr, "Failed parsing document\n"); + return 1; + } + + /* We're done with this */ + free(buf); /* At this point, the DOM tree can be accessed through c->document */ /* Let's dump it to stdout */ |