From c1671f37b1a6b8872d736bfdcee25770dbbd5a06 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Wed, 3 Oct 2012 19:24:58 +0100 Subject: reduce talloc usage to box tree layout only --- render/box_construct.c | 114 +++++++++++++++++++++++++++---------------------- render/box_normalise.c | 17 ++++---- render/html.c | 98 ++++++++++++++++++++++++++---------------- render/html_internal.h | 2 + render/layout.c | 4 +- render/textplain.c | 41 +++++++++++------- 6 files changed, 162 insertions(+), 114 deletions(-) (limited to 'render') diff --git a/render/box_construct.c b/render/box_construct.c index 23896717f..c34c0af96 100644 --- a/render/box_construct.c +++ b/render/box_construct.c @@ -60,6 +60,8 @@ struct box_construct_ctx { struct box *root_box; /**< Root box in the tree */ box_construct_complete_cb cb; /**< Callback to invoke on completion */ + + int *bctx; /**< talloc context */ }; /** @@ -162,6 +164,14 @@ bool xml_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb) { struct box_construct_ctx *ctx; + if (c->bctx == NULL) { + /* create a context allocation for this box tree */ + c->bctx = talloc_zero(0, int); + if (c->bctx == NULL) { + return false; + } + } + ctx = malloc(sizeof(*ctx)); if (ctx == NULL) return false; @@ -170,6 +180,7 @@ bool xml_to_box(dom_node *n, html_content *c, box_construct_complete_cb cb) ctx->n = dom_node_ref(n); ctx->root_box = NULL; ctx->cb = cb; + ctx->bctx = c->bctx; schedule(0, (schedule_callback_fn) convert_xml_to_box, ctx); @@ -568,13 +579,13 @@ void convert_xml_to_box(struct box_construct_ctx *ctx) * \return True on success, false on memory exhaustion */ static bool box_construct_marker(struct box *box, const char *title, - html_content *content, struct box *parent) + struct box_construct_ctx *ctx, struct box *parent) { lwc_string *image_uri; struct box *marker; marker = box_create(NULL, box->style, false, NULL, NULL, title, - NULL, content); + NULL, ctx->bctx); if (marker == false) return false; @@ -629,7 +640,7 @@ static bool box_construct_marker(struct box *box, const char *title, } } - marker->text = talloc_array(content, char, 20); + marker->text = talloc_array(ctx->bctx, char, 20); if (marker->text == NULL) return false; @@ -656,8 +667,8 @@ static bool box_construct_marker(struct box *box, const char *title, if (error != NSERROR_OK) return false; - if (html_fetch_object(content, url, marker, image_types, - content->base.available_width, 1000, false) == + if (html_fetch_object(ctx->content, url, marker, image_types, + ctx->content->base.available_width, 1000, false) == false) { nsurl_unref(url); return false; @@ -709,7 +720,7 @@ static void box_construct_generate(dom_node *n, html_content *content, /** \todo Not wise to drop const from the computed style */ gen = box_create(NULL, (css_computed_style *) style, - false, NULL, NULL, NULL, NULL, content); + false, NULL, NULL, NULL, NULL, content->bctx); if (gen == NULL) { return; } @@ -859,7 +870,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, if (t == NULL) return false; - props.title = talloc_strdup(ctx->content, t); + props.title = talloc_strdup(ctx->bctx, t); free(t); @@ -882,7 +893,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, box = box_create(styles, styles->styles[CSS_PSEUDO_ELEMENT_NONE], false, props.href, props.target, props.title, id, - ctx->content); + ctx->bctx); if (box == NULL) return false; @@ -1001,7 +1012,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, "Root box must not be inline or floated"); props.inline_container = box_create(NULL, NULL, false, NULL, - NULL, NULL, NULL, ctx->content); + NULL, NULL, NULL, ctx->bctx); if (props.inline_container == NULL) return false; @@ -1048,7 +1059,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, if (css_computed_display(box->style, props.node_is_root) == CSS_DISPLAY_LIST_ITEM) { /* List item: compute marker */ - if (box_construct_marker(box, props.title, ctx->content, + if (box_construct_marker(box, props.title, ctx, props.containing_block) == false) return false; } @@ -1059,7 +1070,7 @@ bool box_construct_element(struct box_construct_ctx *ctx, /* Float: insert a float between the parent and box. */ struct box *flt = box_create(NULL, NULL, false, props.href, props.target, props.title, - NULL, ctx->content); + NULL, ctx->bctx); if (flt == NULL) return false; @@ -1118,7 +1129,7 @@ void box_construct_element_after(dom_node *n, html_content *content) if (props.inline_container == NULL) { /* Create inline container if we don't have one */ props.inline_container = box_create(NULL, NULL, false, - NULL, NULL, NULL, NULL, content); + NULL, NULL, NULL, NULL, content->bctx); if (props.inline_container == NULL) return; @@ -1131,7 +1142,7 @@ void box_construct_element_after(dom_node *n, html_content *content) inline_end = box_create(NULL, box->style, false, box->href, box->target, box->title, box->id == NULL ? NULL : - lwc_string_ref(box->id), content); + lwc_string_ref(box->id), content->bctx); if (inline_end != NULL) { inline_end->type = BOX_INLINE_END; @@ -1206,7 +1217,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) * (i.e. this box is the first child of its parent, or * was preceded by block-level siblings) */ props.inline_container = box_create(NULL, NULL, false, - NULL, NULL, NULL, NULL, ctx->content); + NULL, NULL, NULL, NULL, ctx->bctx); if (props.inline_container == NULL) { free(text); return false; @@ -1222,7 +1233,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) box = box_create(NULL, (css_computed_style *) props.parent_style, false, props.href, props.target, props.title, - NULL, ctx->content); + NULL, ctx->bctx); if (box == NULL) { free(text); return false; @@ -1230,7 +1241,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) box->type = BOX_TEXT; - box->text = talloc_strdup(ctx->content, text); + box->text = talloc_strdup(ctx->bctx, text); free(text); if (box->text == NULL) return false; @@ -1324,7 +1335,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) * siblings) */ props.inline_container = box_create(NULL, NULL, false, NULL, NULL, NULL, NULL, - ctx->content); + ctx->bctx); if (props.inline_container == NULL) { free(text); return false; @@ -1341,7 +1352,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) box = box_create(NULL, (css_computed_style *) props.parent_style, false, props.href, props.target, props.title, - NULL, ctx->content); + NULL, ctx->bctx); if (box == NULL) { free(text); return false; @@ -1349,7 +1360,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) box->type = BOX_TEXT; - box->text = talloc_strdup(ctx->content, current); + box->text = talloc_strdup(ctx->bctx, current); if (box->text == NULL) { free(text); return false; @@ -1367,7 +1378,7 @@ bool box_construct_text(struct box_construct_ctx *ctx) /* Linebreak: create new inline container */ props.inline_container = box_create(NULL, NULL, false, NULL, NULL, NULL, NULL, - ctx->content); + ctx->bctx); if (props.inline_container == NULL) { free(text); return false; @@ -1656,7 +1667,7 @@ bool box_a(BOX_SPECIAL_PARAMS) else { /* 6.16 says that frame names must begin with [a-zA-Z] * This doesn't match reality, so just take anything */ - box->target = talloc_strdup(content, + box->target = talloc_strdup(content->bctx, dom_string_data(s)); if (!box->target) { dom_string_unref(s); @@ -1697,7 +1708,7 @@ bool box_image(BOX_SPECIAL_PARAMS) dom_string_unref(s); if (alt == NULL) return false; - box->text = talloc_strdup(content, alt); + box->text = talloc_strdup(content->bctx, alt); free(alt); if (box->text == NULL) return false; @@ -1802,7 +1813,7 @@ bool box_object(BOX_SPECIAL_PARAMS) if (box->usemap && box->usemap[0] == '#') box->usemap++; - params = talloc(content, struct object_params); + params = talloc(content->bctx, struct object_params); if (params == NULL) return false; @@ -2035,11 +2046,11 @@ bool box_frameset(BOX_SPECIAL_PARAMS) return true; } - content->frameset = talloc_zero(content, struct content_html_frames); + content->frameset = talloc_zero(content->bctx, struct content_html_frames); if (!content->frameset) return false; - ok = box_create_frameset(content->frameset, n, content); + ok = box_create_frameset(content->frameset, n, content->bctx); if (ok) box->type = BOX_NONE; @@ -2402,7 +2413,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS) } /* create a new iframe */ - iframe = talloc(content, struct content_html_iframe); + iframe = talloc(content->bctx, struct content_html_iframe); if (iframe == NULL) { nsurl_unref(url); return false; @@ -2425,7 +2436,7 @@ bool box_iframe(BOX_SPECIAL_PARAMS) /* fill in specified values */ err = dom_element_get_attribute(n, kstr_name, &s); if (err == DOM_NO_ERR && s != NULL) { - iframe->name = talloc_strdup(content, dom_string_data(s)); + iframe->name = talloc_strdup(content->bctx, dom_string_data(s)); dom_string_unref(s); } @@ -2533,30 +2544,31 @@ bool box_input(BOX_SPECIAL_PARAMS) goto no_memory; inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, - content); + content->bctx); if (inline_container == NULL) goto no_memory; inline_container->type = BOX_INLINE_CONTAINER; inline_box = box_create(NULL, box->style, false, 0, 0, - box->title, 0, content); + box->title, 0, content->bctx); if (inline_box == NULL) goto no_memory; inline_box->type = BOX_TEXT; if (box->gadget->value != NULL) - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, box->gadget->value); else if (box->gadget->type == GADGET_SUBMIT) - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, messages_get("Form_Submit")); else if (box->gadget->type == GADGET_RESET) - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, messages_get("Form_Reset")); else - inline_box->text = talloc_strdup(content, "Button"); + inline_box->text = talloc_strdup(content->bctx, + "Button"); if (inline_box->text == NULL) goto no_memory; @@ -2631,18 +2643,18 @@ bool box_input_text(BOX_SPECIAL_PARAMS, bool password) box->type = BOX_INLINE_BLOCK; - inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content); + inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content->bctx); if (!inline_container) return false; inline_container->type = BOX_INLINE_CONTAINER; inline_box = box_create(NULL, box->style, false, 0, 0, box->title, 0, - content); + content->bctx); if (!inline_box) return false; inline_box->type = BOX_TEXT; if (password) { inline_box->length = strlen(box->gadget->value); - inline_box->text = talloc_array(content, char, + inline_box->text = talloc_array(content->bctx, char, inline_box->length + 1); if (!inline_box->text) return false; @@ -2654,7 +2666,7 @@ bool box_input_text(BOX_SPECIAL_PARAMS, bool password) char *text = cnv_space2nbsp(box->gadget->value); if (!text) return false; - inline_box->text = talloc_strdup(content, text); + inline_box->text = talloc_strdup(content->bctx, text); free(text); if (!inline_box->text) return false; @@ -2795,12 +2807,12 @@ bool box_select(BOX_SPECIAL_PARAMS) box->gadget = gadget; gadget->box = box; - inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content); + inline_container = box_create(NULL, 0, false, 0, 0, 0, 0, content->bctx); if (inline_container == NULL) goto no_memory; inline_container->type = BOX_INLINE_CONTAINER; inline_box = box_create(NULL, box->style, false, 0, 0, box->title, 0, - content); + content->bctx); if (inline_box == NULL) goto no_memory; inline_box->type = BOX_TEXT; @@ -2816,13 +2828,13 @@ bool box_select(BOX_SPECIAL_PARAMS) } if (gadget->data.select.num_selected == 0) - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, messages_get("Form_None")); else if (gadget->data.select.num_selected == 1) - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, gadget->data.select.current->text); else - inline_box->text = talloc_strdup(content, + inline_box->text = talloc_strdup(content->bctx, messages_get("Form_Many")); if (inline_box->text == NULL) goto no_memory; @@ -2927,7 +2939,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS) box->gadget->box = box; inline_container = box_create(NULL, 0, false, 0, 0, box->title, 0, - content); + content->bctx); if (inline_container == NULL) return false; inline_container->type = BOX_INLINE_CONTAINER; @@ -2947,7 +2959,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS) while (true) { /* BOX_TEXT */ len = strcspn(current, "\r\n"); - s = talloc_strndup(content, current, len); + s = talloc_strndup(content->bctx, current, len); if (s == NULL) { if (area_data != NULL) dom_string_unref(area_data); @@ -2955,7 +2967,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS) } inline_box = box_create(NULL, box->style, false, 0, 0, - box->title, 0, content); + box->title, 0, content->bctx); if (inline_box == NULL) { if (area_data != NULL) dom_string_unref(area_data); @@ -2973,7 +2985,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS) /* BOX_BR */ br_box = box_create(NULL, box->style, false, 0, 0, box->title, - 0, content); + 0, content->bctx); if (br_box == NULL) { if (area_data != NULL) dom_string_unref(area_data); @@ -3015,7 +3027,7 @@ bool box_embed(BOX_SPECIAL_PARAMS) box_is_root(n)) == CSS_DISPLAY_NONE) return true; - params = talloc(content, struct object_params); + params = talloc(content->bctx, struct object_params); if (params == NULL) return false; @@ -3086,7 +3098,7 @@ bool box_embed(BOX_SPECIAL_PARAMS) return false; } - param = talloc(content, struct object_param); + param = talloc(content->bctx, struct object_param); if (param == NULL) { dom_string_unref(value); dom_string_unref(name); @@ -3094,10 +3106,10 @@ bool box_embed(BOX_SPECIAL_PARAMS) return false; } - param->name = talloc_strdup(content, dom_string_data(name)); - param->value = talloc_strdup(content, dom_string_data(value)); + param->name = talloc_strdup(content->bctx, dom_string_data(name)); + param->value = talloc_strdup(content->bctx, dom_string_data(value)); param->type = NULL; - param->valuetype = talloc_strdup(content, "data"); + param->valuetype = talloc_strdup(content->bctx, "data"); param->next = NULL; dom_string_unref(value); diff --git a/render/box_normalise.c b/render/box_normalise.c index 8428b8455..42b20cbb7 100644 --- a/render/box_normalise.c +++ b/render/box_normalise.c @@ -32,7 +32,6 @@ #include "render/html_internal.h" #include "render/table.h" #include "utils/log.h" -#include "utils/talloc.h" /* Define to enable box normalise debug */ #undef BOX_NORMALISE_DEBUG @@ -163,7 +162,7 @@ bool box_normalise_block(struct box *block, html_content *c) return false; table = box_create(NULL, style, true, block->href, - block->target, NULL, NULL, c); + block->target, NULL, NULL, c->bctx); if (table == NULL) { css_computed_style_destroy(style); return false; @@ -267,7 +266,7 @@ bool box_normalise_table(struct box *table, html_content * c) } row_group = box_create(NULL, style, true, table->href, - table->target, NULL, NULL, c); + table->target, NULL, NULL, c->bctx); if (row_group == NULL) { css_computed_style_destroy(style); free(col_info.spans); @@ -354,7 +353,7 @@ bool box_normalise_table(struct box *table, html_content * c) } row_group = box_create(NULL, style, true, table->href, - table->target, NULL, NULL, c); + table->target, NULL, NULL, c->bctx); if (row_group == NULL) { css_computed_style_destroy(style); free(col_info.spans); @@ -371,7 +370,7 @@ bool box_normalise_table(struct box *table, html_content * c) } row = box_create(NULL, style, true, row_group->href, - row_group->target, NULL, NULL, c); + row_group->target, NULL, NULL, c->bctx); if (row == NULL) { css_computed_style_destroy(style); box_free(row_group); @@ -491,7 +490,7 @@ bool box_normalise_table_spans(struct box *table, struct span_info *spans, cell = box_create(NULL, style, true, table_row->href, table_row->target, - NULL, NULL, c); + NULL, NULL, c->bctx); if (cell == NULL) { css_computed_style_destroy( style); @@ -598,7 +597,7 @@ bool box_normalise_table_row_group(struct box *row_group, return false; row = box_create(NULL, style, true, row_group->href, - row_group->target, NULL, NULL, c); + row_group->target, NULL, NULL, c->bctx); if (row == NULL) { css_computed_style_destroy(style); return false; @@ -674,7 +673,7 @@ bool box_normalise_table_row_group(struct box *row_group, } row = box_create(NULL, style, true, row_group->href, - row_group->target, NULL, NULL, c); + row_group->target, NULL, NULL, c->bctx); if (row == NULL) { css_computed_style_destroy(style); return false; @@ -743,7 +742,7 @@ bool box_normalise_table_row(struct box *row, return false; cell = box_create(NULL, style, true, row->href, - row->target, NULL, NULL, c); + row->target, NULL, NULL, c->bctx); if (cell == NULL) { css_computed_style_destroy(style); return false; diff --git a/render/html.c b/render/html.c index 7be2dabe5..b6aabb6a3 100644 --- a/render/html.c +++ b/render/html.c @@ -93,7 +93,7 @@ static void html_destroy_objects(html_content *html) } html->object_list = victim->next; - talloc_free(victim); + free(victim); } } @@ -280,6 +280,7 @@ html_create_html_data(html_content *c, const http_parameter *params) c->base_url = nsurl_ref(content_get_url(&c->base)); c->base_target = NULL; c->aborted = false; + c->bctx = NULL; c->layout = NULL; c->background_colour = NS_TRANSPARENT; c->stylesheet_count = 0; @@ -313,7 +314,7 @@ html_create_html_data(html_content *c, const http_parameter *params) nerror = http_parameter_list_find_item(params, html_charset, &charset); if (nerror == NSERROR_OK) { - c->encoding = talloc_strdup(c, lwc_string_data(charset)); + c->encoding = strdup(lwc_string_data(charset)); lwc_string_unref(charset); @@ -341,7 +342,7 @@ html_create_html_data(html_content *c, const http_parameter *params) if ((c->parser == NULL) && (c->encoding != NULL)) { /* Ok, we don't support the declared encoding. Bailing out * isn't exactly user-friendly, so fall back to autodetect */ - talloc_free(c->encoding); + free(c->encoding); c->encoding = NULL; c->parser = dom_hubbub_parser_create(c->encoding, @@ -389,20 +390,20 @@ html_create(const content_handler *handler, html_content *html; nserror error; - html = talloc_zero(0, html_content); + html = calloc(1, sizeof(html_content)); if (html == NULL) return NSERROR_NOMEM; error = content__init(&html->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(html); + free(html); return error; } error = html_create_html_data(html, params); if (error != NSERROR_OK) { - talloc_free(html); + free(html); return error; } @@ -429,10 +430,16 @@ html_process_encoding_change(struct content *c, encoding = dom_hubbub_parser_get_encoding(html->parser, &html->encoding_source); + if (encoding == NULL) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(c, CONTENT_MSG_ERROR, msg_data); + return false; + } + if (html->encoding != NULL) - talloc_free(html->encoding); + free(html->encoding); - html->encoding = talloc_strdup(c, encoding); + html->encoding = strdup(encoding); if (html->encoding == NULL) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); @@ -454,8 +461,8 @@ html_process_encoding_change(struct content *c, if (html->parser == NULL) { /* Ok, we don't support the declared encoding. Bailing out * isn't exactly user-friendly, so fall back to Windows-1252 */ - talloc_free(html->encoding); - html->encoding = talloc_strdup(c, "Windows-1252"); + free(html->encoding); + html->encoding = strdup("Windows-1252"); if (html->encoding == NULL) { msg_data.error = messages_get("NoMemory"); content_broadcast(c, CONTENT_MSG_ERROR, msg_data); @@ -1515,8 +1522,8 @@ html_process_style_element(html_content *c, } /* Extend array */ - stylesheets = talloc_realloc(c, c->stylesheets, - struct html_stylesheet, *index + 1); + stylesheets = realloc(c->stylesheets, + sizeof(struct html_stylesheet) * (*index + 1)); if (stylesheets == NULL) goto no_memory; @@ -1527,7 +1534,7 @@ html_process_style_element(html_content *c, c->stylesheets[(*index)].data.internal = NULL; /* create stylesheet */ - sheet = talloc(c, struct content_css_data); + sheet = calloc(1, sizeof(struct content_css_data)); if (sheet == NULL) { c->stylesheet_count--; goto no_memory; @@ -1537,7 +1544,7 @@ html_process_style_element(html_content *c, nsurl_access(c->base_url), NULL, c->quirks, html_inline_style_done, c); if (error != NSERROR_OK) { - talloc_free(sheet); + free(sheet); c->stylesheet_count--; goto no_memory; } @@ -1548,7 +1555,7 @@ html_process_style_element(html_content *c, exc = dom_node_get_first_child(style, &child); if (exc != DOM_NO_ERR) { nscss_destroy_css_data(sheet); - talloc_free(sheet); + free(sheet); c->stylesheet_count--; goto no_memory; } @@ -1560,7 +1567,7 @@ html_process_style_element(html_content *c, if (exc != DOM_NO_ERR) { dom_node_unref(child); nscss_destroy_css_data(sheet); - talloc_free(sheet); + free(sheet); c->stylesheet_count--; goto no_memory; } @@ -1570,7 +1577,7 @@ html_process_style_element(html_content *c, dom_string_unref(data); dom_node_unref(child); nscss_destroy_css_data(sheet); - talloc_free(sheet); + free(sheet); c->stylesheet_count--; goto no_memory; } @@ -1581,7 +1588,7 @@ html_process_style_element(html_content *c, if (exc != DOM_NO_ERR) { dom_node_unref(child); nscss_destroy_css_data(sheet); - talloc_free(sheet); + free(sheet); c->stylesheet_count--; goto no_memory; } @@ -1599,7 +1606,7 @@ html_process_style_element(html_content *c, c->base.active--; LOG(("%d fetches active", c->base.active)); nscss_destroy_css_data(sheet); - talloc_free(sheet); + free(sheet); sheet = NULL; } @@ -1810,10 +1817,8 @@ html_process_stylesheet(dom_node *node, dom_string *name, void *vctx) LOG(("linked stylesheet %i '%s'", ctx->count, nsurl_access(joined))); /* start fetch */ - stylesheets = talloc_realloc(ctx->c, - ctx->c->stylesheets, - struct html_stylesheet, - ctx->count + 1); + stylesheets = realloc(ctx->c->stylesheets, + sizeof(struct html_stylesheet) * (ctx->count + 1)); if (stylesheets == NULL) { nsurl_unref(joined); goto no_memory; @@ -1882,10 +1887,10 @@ static bool html_find_stylesheets(html_content *c, dom_node *html) * stylesheet 1 is the quirks mode style sheet, * stylesheet 2 is the adblocking stylesheet, * stylesheet 3 is the user stylesheet */ - c->stylesheets = talloc_array(c, struct html_stylesheet, - STYLESHEET_START); - if (c->stylesheets == NULL) + c->stylesheets = calloc(STYLESHEET_START, sizeof(struct html_stylesheet)); + if (c->stylesheets == NULL) { goto html_find_stylesheets_no_memory; + } c->stylesheets[STYLESHEET_BASE].type = HTML_STYLESHEET_EXTERNAL; c->stylesheets[STYLESHEET_BASE].data.external = NULL; @@ -2030,10 +2035,16 @@ html_begin_conversion(html_content *htmlc) /* get encoding */ if (htmlc->encoding == NULL) { const char *encoding; + encoding = dom_hubbub_parser_get_encoding(htmlc->parser, &htmlc->encoding_source); + if (encoding == NULL) { + msg_data.error = messages_get("NoMemory"); + content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data); + return false; + } - htmlc->encoding = talloc_strdup(&htmlc->base, encoding); + htmlc->encoding = strdup(encoding); if (htmlc->encoding == NULL) { msg_data.error = messages_get("NoMemory"); content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data); @@ -2219,7 +2230,7 @@ bool html_fetch_object(html_content *c, nsurl *url, struct box *box, child.charset = c->encoding; child.quirks = c->base.quirks; - object = talloc(c, struct content_html_object); + object = calloc(1, sizeof(struct content_html_object)); if (object == NULL) { return false; } @@ -2237,7 +2248,7 @@ bool html_fetch_object(html_content *c, nsurl *url, struct box *box, html_object_callback, object, &child, object->permitted_types, &object->content); if (error != NSERROR_OK) { - talloc_free(object); + free(object); return error != NSERROR_NOMEM; } @@ -2395,17 +2406,17 @@ static void html_destroy_frameset(struct content_html_frames *frameset) int i; if (frameset->name) { - talloc_free(frameset->name); + free(frameset->name); frameset->name = NULL; } if (frameset->url) { - talloc_free(frameset->url); + free(frameset->url); frameset->url = NULL; } if (frameset->children) { for (i = 0; i < (frameset->rows * frameset->cols); i++) { if (frameset->children[i].name) { - talloc_free(frameset->children[i].name); + free(frameset->children[i].name); frameset->children[i].name = NULL; } if (frameset->children[i].url) { @@ -2415,7 +2426,7 @@ static void html_destroy_frameset(struct content_html_frames *frameset) if (frameset->children[i].children) html_destroy_frameset(&frameset->children[i]); } - talloc_free(frameset->children); + free(frameset->children); frameset->children = NULL; } } @@ -2427,12 +2438,23 @@ static void html_destroy_iframe(struct content_html_iframe *iframe) while ((iframe = next) != NULL) { next = iframe->next; if (iframe->name) - talloc_free(iframe->name); + free(iframe->name); if (iframe->url) { nsurl_unref(iframe->url); iframe->url = NULL; } - talloc_free(iframe); + free(iframe); + } +} + + +static void html_free_layout(html_content *htmlc) +{ + if (htmlc->bctx != NULL) { + /* freeing talloc context should let the entire box + * set be destroyed + */ + talloc_free(htmlc->bctx); } } @@ -2481,7 +2503,7 @@ static void html_destroy(struct content *c) /* Free frameset */ if (html->frameset != NULL) { html_destroy_frameset(html->frameset); - talloc_free(html->frameset); + free(html->frameset); html->frameset = NULL; } @@ -2515,12 +2537,16 @@ static void html_destroy(struct content *c) html->stylesheets[i].data.internal); } } + free(html->stylesheets); /* Free scripts */ html_free_scripts(html); /* Free objects */ html_destroy_objects(html); + + /* free layout */ + html_free_layout(html); } diff --git a/render/html_internal.h b/render/html_internal.h index 9ff0f98cf..53021a15a 100644 --- a/render/html_internal.h +++ b/render/html_internal.h @@ -51,6 +51,8 @@ typedef struct html_content { /** Content has been aborted in the LOADING state */ bool aborted; + /** A talloc context purely for the render box tree */ + int *bctx; /** Box tree, or NULL. */ struct box *layout; /** Document background colour. */ diff --git a/render/layout.c b/render/layout.c index 0523cf9db..d0e3debe0 100644 --- a/render/layout.c +++ b/render/layout.c @@ -2162,7 +2162,7 @@ static bool layout_text_box_split(html_content *content, } /* Create clone of split_box, c2 */ - c2 = talloc_memdup(content, split_box, sizeof *c2); + c2 = talloc_memdup(content->bctx, split_box, sizeof *c2); if (!c2) return false; c2->flags |= CLONE; @@ -2172,7 +2172,7 @@ static bool layout_text_box_split(html_content *content, /* Inside a form text input / textarea, special case */ /* TODO: Move text inputs to core textarea widget and remove * this */ - c2->text = talloc_strndup(content, + c2->text = talloc_strndup(content->bctx, split_box->text + new_length + 1, split_box->length - (new_length + 1)); if (!c2->text) diff --git a/render/textplain.c b/render/textplain.c index 1877f32eb..6cf334fe2 100644 --- a/render/textplain.c +++ b/render/textplain.c @@ -47,7 +47,6 @@ #include "utils/http.h" #include "utils/log.h" #include "utils/messages.h" -#include "utils/talloc.h" #include "utils/utils.h" #include "utils/utf8.h" @@ -212,14 +211,14 @@ nserror textplain_create(const content_handler *handler, nserror error; lwc_string *encoding; - text = talloc_zero(0, textplain_content); + text = calloc(1, sizeof(textplain_content)); if (text == NULL) return NSERROR_NOMEM; error = content__init(&text->base, handler, imime_type, params, llcache, fallback_charset, quirks); if (error != NSERROR_OK) { - talloc_free(text); + free(text); return error; } @@ -232,7 +231,7 @@ nserror textplain_create(const content_handler *handler, error = textplain_create_internal(text, encoding); if (error != NSERROR_OK) { lwc_string_unref(encoding); - talloc_free(text); + free(text); return error; } @@ -268,7 +267,7 @@ nserror textplain_create_internal(textplain_content *c, lwc_string *encoding) textplain_style.size = (nsoption_int(font_size) * FONT_SIZE_SCALE) / 10; - utf8_data = talloc_array(c, char, CHUNK); + utf8_data = malloc(CHUNK); if (utf8_data == NULL) goto no_memory; @@ -281,7 +280,7 @@ nserror textplain_create_internal(textplain_content *c, lwc_string *encoding) &stream); } if (error != PARSERUTILS_OK) { - talloc_free(utf8_data); + free(utf8_data); goto no_memory; } @@ -376,11 +375,11 @@ bool textplain_copy_utf8_data(textplain_content *c, { if (c->utf8_data_size + len >= c->utf8_data_allocated) { /* Compute next multiple of chunk above the required space */ - size_t allocated = (c->utf8_data_size + len + - CHUNK - 1) & ~(CHUNK - 1); - char *utf8_data = talloc_realloc(c, - c->utf8_data, - char, allocated); + size_t allocated; + char *utf8_data; + + allocated = (c->utf8_data_size + len + CHUNK - 1) & ~(CHUNK - 1); + utf8_data = realloc(c->utf8_data, allocated); if (utf8_data == NULL) return false; @@ -484,7 +483,7 @@ void textplain_reformat(struct content *c, int width, int height) if (!line) { text->physical_line = line = - talloc_array(c, struct textplain_line, 1024 + 3); + malloc(sizeof(struct textplain_line) * (1024 + 3)); if (!line) goto no_memory; } @@ -500,8 +499,9 @@ void textplain_reformat(struct content *c, int width, int height) if (term || next_col >= columns) { if (line_count % 1024 == 0) { - line1 = talloc_realloc(c, line, - struct textplain_line, line_count + 1024 + 3); + line1 = realloc(line, + sizeof(struct textplain_line) * + (line_count + 1024 + 3)); if (!line1) goto no_memory; text->physical_line = line = line1; @@ -558,8 +558,17 @@ void textplain_destroy(struct content *c) lwc_string_unref(text->encoding); - if (text->inputstream != NULL) + if (text->inputstream != NULL) { parserutils_inputstream_destroy(text->inputstream); + } + + if (text->physical_line != NULL) { + free(text->physical_line); + } + + if (text->utf8_data != NULL) { + free(text->utf8_data); + } } @@ -571,7 +580,7 @@ nserror textplain_clone(const struct content *old, struct content **newc) const char *data; unsigned long size; - text = talloc_zero(0, textplain_content); + text = calloc(1, sizeof(textplain_content)); if (text == NULL) return NSERROR_NOMEM; -- cgit v1.2.3