diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2014-11-26 17:26:51 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2014-12-03 12:25:52 +0100 |
commit | f1bfe4b861621ad7554670acf91cb029e4482569 (patch) | |
tree | 35fc70c4643a8ad04e1910d271b5f65916429aec | |
parent | c4a45e25b92269e9e44594fd410b272718d939bc (diff) | |
download | mupdf-f1bfe4b861621ad7554670acf91cb029e4482569.tar.xz |
html: Free inline style properties at the end.
-rw-r--r-- | include/mupdf/html.h | 1 | ||||
-rw-r--r-- | source/html/css-apply.c | 15 | ||||
-rw-r--r-- | source/html/css-parse.c | 2 |
3 files changed, 12 insertions, 6 deletions
diff --git a/include/mupdf/html.h b/include/mupdf/html.h index 073145ed..64ee1003 100644 --- a/include/mupdf/html.h +++ b/include/mupdf/html.h @@ -38,6 +38,7 @@ struct fz_css_rule_s { fz_css_selector *selector; fz_css_property *declaration; + fz_css_property *garbage; /* for freeing inline style attributes at the end */ fz_css_rule *next; }; diff --git a/source/html/css-apply.c b/source/html/css-apply.c index 81308c82..48d4f04d 100644 --- a/source/html/css-apply.c +++ b/source/html/css-apply.c @@ -476,13 +476,14 @@ add_property(fz_css_match *match, const char *name, fz_css_value *value, int spe } void -fz_match_css(fz_context *ctx, fz_css_match *match, fz_css_rule *rule, fz_xml *node) +fz_match_css(fz_context *ctx, fz_css_match *match, fz_css_rule *css, fz_xml *node) { + fz_css_rule *rule; fz_css_selector *sel; - fz_css_property *prop; + fz_css_property *prop, *head, *tail; const char *s; - while (rule) + for (rule = css; rule; rule = rule->next) { sel = rule->selector; while (sel) @@ -495,19 +496,21 @@ fz_match_css(fz_context *ctx, fz_css_match *match, fz_css_rule *rule, fz_xml *no } sel = sel->next; } - rule = rule->next; } s = fz_xml_att(node, "style"); if (s) { - prop = fz_parse_css_properties(ctx, s); + head = tail = prop = fz_parse_css_properties(ctx, s); while (prop) { add_property(match, prop->name, prop->value, INLINE_SPECIFICITY); + tail = prop; prop = prop->next; } - // TODO: free props (hitch a ride with fz_css_rule?) + if (tail) + tail->next = css->garbage; + css->garbage = head; } } diff --git a/source/html/css-parse.c b/source/html/css-parse.c index 0b12319f..a751903d 100644 --- a/source/html/css-parse.c +++ b/source/html/css-parse.c @@ -16,6 +16,7 @@ static fz_css_rule *fz_new_css_rule(fz_context *ctx, fz_css_selector *selector, fz_css_rule *rule = fz_malloc_struct(ctx, fz_css_rule); rule->selector = selector; rule->declaration = declaration; + rule->garbage = NULL; rule->next = NULL; return rule; } @@ -119,6 +120,7 @@ void fz_free_css(fz_context *ctx, fz_css_rule *rule) fz_css_rule *next = rule->next; fz_free_css_selector(ctx, rule->selector); fz_free_css_property(ctx, rule->declaration); + fz_free_css_property(ctx, rule->garbage); fz_free(ctx, rule); rule = next; } |