summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@netsurf-browser.org>2010-04-27 21:38:41 +0000
committerDaniel Silverstone <dsilvers@netsurf-browser.org>2010-04-27 21:38:41 +0000
commit30e0cfe7a97a6f36acadf29f8b32a3f4efd85770 (patch)
treef89c698be1ad14b2c439ffd4fbe938ffc902bf36
parent485ac0dad7d12949b7b2ad4cd671909d9b553968 (diff)
downloadnetsurf-30e0cfe7a97a6f36acadf29f8b32a3f4efd85770.tar.gz
netsurf-30e0cfe7a97a6f36acadf29f8b32a3f4efd85770.tar.bz2
First step to fixing memory leaks -- Box model no longer leaks computed styles
svn path=/trunk/netsurf/; revision=10500
-rw-r--r--desktop/textinput.c2
-rw-r--r--render/box.c23
-rw-r--r--render/box.h2
-rw-r--r--render/box_construct.c47
-rw-r--r--render/box_normalise.c16
-rw-r--r--render/html.c2
6 files changed, 56 insertions, 36 deletions
diff --git a/desktop/textinput.c b/desktop/textinput.c
index 5058ce439..0297e952e 100644
--- a/desktop/textinput.c
+++ b/desktop/textinput.c
@@ -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) {
diff --git a/render/box.c b/render/box.c
index e09a4772c..9bb7e59fe 100644
--- a/render/box.c
+++ b/render/box.c
@@ -51,6 +51,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.
*
* \param style style for the box (not copied)
@@ -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;
diff --git a/render/box.h b/render/box.h
index 665565f2f..d1a1994f1 100644
--- a/render/box.h
+++ b/render/box.h
@@ -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);
diff --git a/render/box_construct.c b/render/box_construct.c
index a5ceb2884..f7d92079b 100644
--- a/render/box_construct.c
+++ b/render/box_construct.c
@@ -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);
diff --git a/render/box_normalise.c b/render/box_normalise.c
index fc563e743..8af97535a 100644
--- a/render/box_normalise.c
+++ b/render/box_normalise.c
@@ -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);
diff --git a/render/html.c b/render/html.c
index 8a73b35e2..8d64f9515 100644
--- a/render/html.c
+++ b/render/html.c
@@ -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;