-
Notifications
You must be signed in to change notification settings - Fork 35
/
mem-leak-check.c
51 lines (45 loc) · 1.38 KB
/
mem-leak-check.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* main.c
* Copyright (C) 2017 Kovid Goyal <kovid at kovidgoyal.net>
*
* Distributed under terms of the GPL3 license.
*/
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <libxml/xmlmemory.h>
#include "src/as-libxml.h"
static inline libxml_doc*
convert_tree(GumboOutput *output, Options *opts) {
char *errmsg = NULL;
libxml_doc *doc = NULL;
doc = convert_gumbo_tree_to_libxml_tree(output, opts, &errmsg);
return doc;
}
static inline libxml_doc*
parse_with_options(const char* buffer, size_t buffer_length, Options *opts) {
GumboOutput *output = NULL;
libxml_doc* doc = NULL;
output = gumbo_parse_with_options(&(opts->gumbo_opts), buffer, buffer_length);
doc = convert_tree(output, opts);
gumbo_destroy_output(output);
free_libxml_doc(doc);
return doc;
}
int main(int UNUSED argc, char UNUSED **argv) {
char buf[1024*1024] = {0};
Options opts = {0};
opts.gumbo_opts = kGumboDefaultOptions;
opts.stack_size = 16 * 1024;
opts.gumbo_opts.max_errors = 0;
opts.keep_doctype = 1;
xmlInitParser();
ssize_t sz = read(STDIN_FILENO, buf, (sizeof(buf) / sizeof(buf[0])) - 1);
parse_with_options(buf, (size_t)sz, &opts);
opts.namespace_elements = 1;
opts.sanitize_names = 1;
opts.gumbo_opts.use_xhtml_rules = 1;
parse_with_options(buf, (size_t)sz, &opts);
xmlCleanupParser();
return 0;
}