mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-02-13 21:14:25 +03:00
First step to fixing memory leaks -- Box model no longer leaks computed styles
svn path=/trunk/netsurf/; revision=10500
This commit is contained in:
parent
485ac0dad7
commit
30e0cfe7a9
@ -1984,7 +1984,7 @@ struct box *textarea_insert_break(struct browser_window *bw,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
new_br = box_create(text_box->style, 0, 0, text_box->title, 0,
|
||||
new_br = box_create(text_box->style, false, 0, 0, text_box->title, 0,
|
||||
current_content);
|
||||
new_text = talloc(current_content, struct box);
|
||||
if (!new_text) {
|
||||
|
23
render/box.c
23
render/box.c
@ -50,6 +50,22 @@ struct box_duplicate_llist {
|
||||
};
|
||||
static struct box_duplicate_llist *box_duplicate_last = NULL;
|
||||
|
||||
/**
|
||||
* Destructor for box nodes which own styles
|
||||
*
|
||||
* @param b The box being destroyed.
|
||||
* @return 0 to allow talloc to continue destroying the tree.
|
||||
*/
|
||||
static int
|
||||
free_box_style(struct box *b)
|
||||
{
|
||||
if (b->style != NULL) {
|
||||
css_computed_style_destroy(b->style);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a box tree node.
|
||||
*
|
||||
@ -62,7 +78,7 @@ static struct box_duplicate_llist *box_duplicate_last = NULL;
|
||||
* \return allocated and initialised box, or 0 on memory exhaustion
|
||||
*/
|
||||
|
||||
struct box * box_create(css_computed_style *style,
|
||||
struct box * box_create(css_computed_style *style, bool style_owned,
|
||||
char *href, const char *target, char *title, char *id,
|
||||
void *context)
|
||||
{
|
||||
@ -73,7 +89,10 @@ struct box * box_create(css_computed_style *style,
|
||||
if (!box) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (style_owned == true)
|
||||
talloc_set_destructor(box, free_box_style);
|
||||
|
||||
box->type = BOX_INLINE;
|
||||
box->style = style;
|
||||
box->x = box->y = 0;
|
||||
|
@ -295,7 +295,7 @@ extern const char *TARGET_BLANK;
|
||||
#define UNKNOWN_MAX_WIDTH INT_MAX
|
||||
|
||||
|
||||
struct box * box_create(css_computed_style *style,
|
||||
struct box * box_create(css_computed_style *style, bool style_owned,
|
||||
char *href, const char *target, char *title,
|
||||
char *id, void *context);
|
||||
void box_add_child(struct box *parent, struct box *child);
|
||||
|
@ -325,7 +325,7 @@ bool box_construct_element(xmlNode *n, struct content *content,
|
||||
return false;
|
||||
|
||||
/* create box for this element */
|
||||
box = box_create(style, href, target, title, id, content);
|
||||
box = box_create(style, true, href, target, title, id, content);
|
||||
if (!box)
|
||||
return false;
|
||||
/* set box type from computed display */
|
||||
@ -389,7 +389,7 @@ bool box_construct_element(xmlNode *n, struct content *content,
|
||||
css_computed_float(style) == CSS_FLOAT_LEFT ||
|
||||
css_computed_float(style) == CSS_FLOAT_RIGHT)) {
|
||||
/* this is the first inline in a block: make a container */
|
||||
*inline_container = box_create(0, 0, 0, 0, 0, content);
|
||||
*inline_container = box_create(0, false, 0, 0, 0, 0, content);
|
||||
if (!*inline_container)
|
||||
return false;
|
||||
|
||||
@ -409,7 +409,7 @@ bool box_construct_element(xmlNode *n, struct content *content,
|
||||
href, target, title))
|
||||
return false;
|
||||
|
||||
inline_end = box_create(style, href, target, title, id,
|
||||
inline_end = box_create(style, false, href, target, title, id,
|
||||
content);
|
||||
if (!inline_end)
|
||||
return false;
|
||||
@ -442,7 +442,7 @@ bool box_construct_element(xmlNode *n, struct content *content,
|
||||
lwc_string *image_uri;
|
||||
struct box *marker;
|
||||
|
||||
marker = box_create(style, 0, 0, title, 0, content);
|
||||
marker = box_create(style, false, 0, 0, title, 0, content);
|
||||
if (!marker)
|
||||
return false;
|
||||
|
||||
@ -530,7 +530,7 @@ bool box_construct_element(xmlNode *n, struct content *content,
|
||||
* current node. Note: new parent will be the float */
|
||||
if (css_computed_float(style) == CSS_FLOAT_LEFT ||
|
||||
css_computed_float(style) == CSS_FLOAT_RIGHT) {
|
||||
parent = box_create(0, href, target, title, 0, content);
|
||||
parent = box_create(0, false, href, target, title, 0, content);
|
||||
if (!parent)
|
||||
return false;
|
||||
|
||||
@ -648,7 +648,7 @@ bool box_construct_text(xmlNode *n, struct content *content,
|
||||
|
||||
if (!*inline_container) {
|
||||
/* this is the first inline node: make a container */
|
||||
*inline_container = box_create(0, 0, 0, 0, 0, content);
|
||||
*inline_container = box_create(0, false, 0, 0, 0, 0, content);
|
||||
if (!*inline_container) {
|
||||
free(text);
|
||||
return false;
|
||||
@ -660,7 +660,7 @@ bool box_construct_text(xmlNode *n, struct content *content,
|
||||
}
|
||||
|
||||
/** \todo Dropping const here is not clever */
|
||||
box = box_create((css_computed_style *) parent_style,
|
||||
box = box_create((css_computed_style *) parent_style, false,
|
||||
href, target, title, 0, content);
|
||||
if (!box) {
|
||||
free(text);
|
||||
@ -761,7 +761,7 @@ bool box_construct_text(xmlNode *n, struct content *content,
|
||||
current[len] = 0;
|
||||
|
||||
if (!*inline_container) {
|
||||
*inline_container = box_create(0, 0, 0, 0, 0,
|
||||
*inline_container = box_create(0, false, 0, 0, 0, 0,
|
||||
content);
|
||||
if (!*inline_container) {
|
||||
free(text);
|
||||
@ -775,7 +775,7 @@ bool box_construct_text(xmlNode *n, struct content *content,
|
||||
}
|
||||
|
||||
/** \todo Dropping const isn't clever */
|
||||
box = box_create((css_computed_style *) parent_style,
|
||||
box = box_create((css_computed_style *) parent_style, false,
|
||||
href, target, title, 0, content);
|
||||
if (!box) {
|
||||
free(text);
|
||||
@ -814,9 +814,9 @@ bool box_construct_text(xmlNode *n, struct content *content,
|
||||
}
|
||||
|
||||
|
||||
static void *myrealloc(void *ptr, size_t len, void *pw)
|
||||
static void *ns_css_computed_style_alloc(void *ptr, size_t len, void *pw)
|
||||
{
|
||||
return talloc_realloc_size(pw, ptr, len);
|
||||
return realloc(ptr, len);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -842,7 +842,7 @@ css_computed_style *box_get_style(struct content *c,
|
||||
(uint8_t *) s, strlen(s),
|
||||
c->data.html.encoding, content__get_url(c),
|
||||
c->data.html.quirks != BINDING_QUIRKS_MODE_NONE,
|
||||
myrealloc, c);
|
||||
ns_css_computed_style_alloc, c);
|
||||
|
||||
xmlFree(s);
|
||||
|
||||
@ -852,7 +852,8 @@ css_computed_style *box_get_style(struct content *c,
|
||||
|
||||
/* Select partial style for element */
|
||||
partial = nscss_get_style(c, n, CSS_PSEUDO_ELEMENT_NONE,
|
||||
CSS_MEDIA_SCREEN, inline_style, myrealloc, c);
|
||||
CSS_MEDIA_SCREEN, inline_style,
|
||||
ns_css_computed_style_alloc, c);
|
||||
|
||||
/* No longer need inline style */
|
||||
if (inline_style != NULL)
|
||||
@ -1257,7 +1258,7 @@ struct box_result box_applet(xmlNode *n, struct box_status *status,
|
||||
if (!po)
|
||||
return (struct box_result) {0, false, true};
|
||||
|
||||
box = box_create(style, status->href, 0, status->id,
|
||||
box = box_create(style, false, status->href, 0, status->id,
|
||||
status->content->data.html.box_pool);
|
||||
if (!box) {
|
||||
free(po);
|
||||
@ -1726,13 +1727,13 @@ bool box_input(BOX_SPECIAL_PARAMS)
|
||||
if (!box_button(n, content, box, 0))
|
||||
goto no_memory;
|
||||
|
||||
inline_container = box_create(0, 0, 0, 0, 0, content);
|
||||
inline_container = box_create(0, false, 0, 0, 0, 0, content);
|
||||
if (!inline_container)
|
||||
goto no_memory;
|
||||
|
||||
inline_container->type = BOX_INLINE_CONTAINER;
|
||||
|
||||
inline_box = box_create(box->style, 0, 0, box->title, 0,
|
||||
inline_box = box_create(box->style, false, 0, 0, box->title, 0,
|
||||
content);
|
||||
if (!inline_box)
|
||||
goto no_memory;
|
||||
@ -1818,11 +1819,11 @@ bool box_input_text(BOX_SPECIAL_PARAMS, bool password)
|
||||
|
||||
box->type = BOX_INLINE_BLOCK;
|
||||
|
||||
inline_container = box_create(0, 0, 0, 0, 0, content);
|
||||
inline_container = box_create(0, false, 0, 0, 0, 0, content);
|
||||
if (!inline_container)
|
||||
return false;
|
||||
inline_container->type = BOX_INLINE_CONTAINER;
|
||||
inline_box = box_create(box->style, 0, 0, box->title, 0, content);
|
||||
inline_box = box_create(box->style, false, 0, 0, box->title, 0, content);
|
||||
if (!inline_box)
|
||||
return false;
|
||||
inline_box->type = BOX_TEXT;
|
||||
@ -1917,11 +1918,11 @@ bool box_select(BOX_SPECIAL_PARAMS)
|
||||
box->gadget = gadget;
|
||||
gadget->box = box;
|
||||
|
||||
inline_container = box_create(0, 0, 0, 0, 0, content);
|
||||
inline_container = box_create(0, false, 0, 0, 0, 0, content);
|
||||
if (!inline_container)
|
||||
goto no_memory;
|
||||
inline_container->type = BOX_INLINE_CONTAINER;
|
||||
inline_box = box_create(box->style, 0, 0, box->title, 0, content);
|
||||
inline_box = box_create(box->style, false, 0, 0, box->title, 0, content);
|
||||
if (!inline_box)
|
||||
goto no_memory;
|
||||
inline_box->type = BOX_TEXT;
|
||||
@ -2040,7 +2041,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS)
|
||||
return false;
|
||||
box->gadget->box = box;
|
||||
|
||||
inline_container = box_create(0, 0, 0, box->title, 0, content);
|
||||
inline_container = box_create(0, false, 0, 0, box->title, 0, content);
|
||||
if (!inline_container)
|
||||
return false;
|
||||
inline_container->type = BOX_INLINE_CONTAINER;
|
||||
@ -2092,7 +2093,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS)
|
||||
return false;
|
||||
}
|
||||
|
||||
inline_box = box_create(box->style, 0, 0, box->title, 0,
|
||||
inline_box = box_create(box->style, false, 0, 0, box->title, 0,
|
||||
content);
|
||||
if (!inline_box) {
|
||||
xmlFree(string);
|
||||
@ -2110,7 +2111,7 @@ bool box_textarea(BOX_SPECIAL_PARAMS)
|
||||
break;
|
||||
|
||||
/* BOX_BR */
|
||||
br_box = box_create(box->style, 0, 0, box->title, 0, content);
|
||||
br_box = box_create(box->style, false, 0, 0, box->title, 0, content);
|
||||
if (!br_box) {
|
||||
xmlFree(string);
|
||||
xmlBufferFree(buf);
|
||||
|
@ -166,7 +166,7 @@ bool box_normalise_block(struct box *block, struct content *c)
|
||||
if (style == NULL)
|
||||
return false;
|
||||
|
||||
table = box_create(style, block->href, block->target,
|
||||
table = box_create(style, true, block->href, block->target,
|
||||
NULL, NULL, c);
|
||||
if (table == NULL) {
|
||||
css_computed_style_destroy(style);
|
||||
@ -262,7 +262,7 @@ bool box_normalise_table(struct box *table, struct content * c)
|
||||
return false;
|
||||
}
|
||||
|
||||
row_group = box_create(style, table->href,
|
||||
row_group = box_create(style, true, table->href,
|
||||
table->target, NULL, NULL, c);
|
||||
if (row_group == NULL) {
|
||||
css_computed_style_destroy(style);
|
||||
@ -341,7 +341,7 @@ bool box_normalise_table(struct box *table, struct content * c)
|
||||
return false;
|
||||
}
|
||||
|
||||
row_group = box_create(style, table->href,
|
||||
row_group = box_create(style, true, table->href,
|
||||
table->target, NULL, NULL, c);
|
||||
if (row_group == NULL) {
|
||||
css_computed_style_destroy(style);
|
||||
@ -358,7 +358,7 @@ bool box_normalise_table(struct box *table, struct content * c)
|
||||
return false;
|
||||
}
|
||||
|
||||
row = box_create(style, row_group->href,
|
||||
row = box_create(style, true, row_group->href,
|
||||
row_group->target, NULL, NULL, c);
|
||||
if (row == NULL) {
|
||||
css_computed_style_destroy(style);
|
||||
@ -467,7 +467,7 @@ bool box_normalise_table_spans(struct box *table, struct span_info *spans,
|
||||
if (style == NULL)
|
||||
return false;
|
||||
|
||||
cell = box_create(style,
|
||||
cell = box_create(style, true,
|
||||
table_row->href,
|
||||
table_row->target,
|
||||
NULL, NULL, c);
|
||||
@ -568,7 +568,7 @@ bool box_normalise_table_row_group(struct box *row_group,
|
||||
if (style == NULL)
|
||||
return false;
|
||||
|
||||
row = box_create(style, row_group->href,
|
||||
row = box_create(style, true, row_group->href,
|
||||
row_group->target, NULL, NULL, c);
|
||||
if (row == NULL) {
|
||||
css_computed_style_destroy(style);
|
||||
@ -637,7 +637,7 @@ bool box_normalise_table_row_group(struct box *row_group,
|
||||
return false;
|
||||
}
|
||||
|
||||
row = box_create(style, row_group->href,
|
||||
row = box_create(style, true, row_group->href,
|
||||
row_group->target, NULL, NULL, c);
|
||||
if (row == NULL) {
|
||||
css_computed_style_destroy(style);
|
||||
@ -695,7 +695,7 @@ bool box_normalise_table_row(struct box *row,
|
||||
if (style == NULL)
|
||||
return false;
|
||||
|
||||
cell = box_create(style, row->href, row->target,
|
||||
cell = box_create(style, true, row->href, row->target,
|
||||
NULL, NULL, c);
|
||||
if (cell == NULL) {
|
||||
css_computed_style_destroy(style);
|
||||
|
@ -1600,7 +1600,7 @@ void html_object_failed(struct box *box, struct content *content,
|
||||
if (box->next) {
|
||||
/* split this inline container into two inline
|
||||
* containers */
|
||||
ic = box_create(0, 0, 0, 0, 0, content);
|
||||
ic = box_create(0, false, 0, 0, 0, 0, content);
|
||||
if (!ic) {
|
||||
union content_msg_data msg_data;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user