summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-01-05 15:31:59 (GMT)
committer Daniel Silverstone <dsilvers@digital-scurf.org>2014-01-05 15:31:59 (GMT)
commit578704d5a4df0fc7001efe64a5abb343fd2f2b70 (patch)
tree5138682bf350e451fca2cf8c97ae76d635841d1e
parent1e38192e17e7003bf464beaedd3743d883c8d51c (diff)
downloadlibdom-578704d5a4df0fc7001efe64a5abb343fd2f2b70.tar.gz
libdom-578704d5a4df0fc7001efe64a5abb343fd2f2b70.tar.bz2
Remove a bunch of leaks but not reffing dom nodes from dom nodes
-rw-r--r--src/html/html_form_element.c58
-rw-r--r--src/html/html_form_element.h2
-rw-r--r--src/html/html_select_element.c94
-rw-r--r--src/html/html_select_element.h2
4 files changed, 75 insertions, 81 deletions
diff --git a/src/html/html_form_element.c b/src/html/html_form_element.c
index 8ce94ab..fac717b 100644
--- a/src/html/html_form_element.c
+++ b/src/html/html_form_element.c
@@ -70,8 +70,6 @@ dom_exception _dom_html_form_element_initialise(struct dom_html_document *doc,
doc->memoised[hds_FORM],
namespace, prefix);
- ele->col = NULL;
-
return err;
}
@@ -82,8 +80,6 @@ dom_exception _dom_html_form_element_initialise(struct dom_html_document *doc,
*/
void _dom_html_form_element_finalise(struct dom_html_form_element *ele)
{
- if (ele->col != NULL)
- dom_html_collection_unref(ele->col);
_dom_html_element_finalise(&ele->base);
}
@@ -144,23 +140,13 @@ dom_exception dom_html_form_element_get_elements(dom_html_form_element *ele,
struct dom_html_collection **col)
{
dom_exception err;
-
- if (ele->col == NULL) {
- dom_html_document *doc = (dom_html_document *) dom_node_get_owner(ele);
- assert(doc != NULL);
- err = _dom_html_collection_create(doc,
- (dom_node_internal *) doc,
- _dom_is_form_control, ele, col);
- if (err != DOM_NO_ERR)
- return err;
-
- ele->col = *col;
- }
-
- *col = ele->col;
- dom_html_collection_ref(*col);
-
- return DOM_NO_ERR;
+ dom_html_document *doc = (dom_html_document *) dom_node_get_owner(ele);
+
+ assert(doc != NULL);
+ err = _dom_html_collection_create(doc,
+ (dom_node_internal *) doc,
+ _dom_is_form_control, ele, col);
+ return err;
}
/**
@@ -174,18 +160,22 @@ dom_exception dom_html_form_element_get_length(dom_html_form_element *ele,
uint32_t *len)
{
dom_exception err;
+ dom_html_document *doc = (dom_html_document *) dom_node_get_owner(ele);
+ dom_html_collection *col;
+
+ assert(doc != NULL);
+ err = _dom_html_collection_create(doc,
+ (dom_node_internal *) doc,
+ _dom_is_form_control, ele, &col);
+ if (err != DOM_NO_ERR)
+ return err;
- if (ele->col == NULL) {
- dom_html_document *doc = (dom_html_document *) dom_node_get_owner(ele);
- assert(doc != NULL);
- err = _dom_html_collection_create(doc,
- (dom_node_internal *) doc,
- _dom_is_form_control, ele, &ele->col);
- if (err != DOM_NO_ERR)
- return err;
- }
- return dom_html_collection_get_length(ele->col, len);
+ err = dom_html_collection_get_length(col, len);
+
+ dom_html_collection_unref(col);
+
+ return err;
}
#define SIMPLE_GET_SET(attr) \
@@ -287,7 +277,11 @@ static bool _dom_is_form_control(struct dom_node_internal *node, void *ctx)
assert(node->type == DOM_ELEMENT_NODE);
-
+
+ /* This should check the form of each element *AND* node that
+ * buttons leak the forms too! ARGH
+ */
+
/* Form controls are INPUT TEXTAREA SELECT and BUTTON */
if (dom_string_caseless_isequal(node->name,
doc->memoised[hds_INPUT]))
diff --git a/src/html/html_form_element.h b/src/html/html_form_element.h
index 1ee9878..67a1080 100644
--- a/src/html/html_form_element.h
+++ b/src/html/html_form_element.h
@@ -17,8 +17,6 @@ struct dom_html_collection;
struct dom_html_form_element {
struct dom_html_element base;
/**< The base class */
- struct dom_html_collection *col;
- /**< The collection of form controls */
};
/* Create a dom_html_form_element object */
diff --git a/src/html/html_select_element.c b/src/html/html_select_element.c
index 8de5dff..c02f0bd 100644
--- a/src/html/html_select_element.c
+++ b/src/html/html_select_element.c
@@ -63,7 +63,6 @@ dom_exception _dom_html_select_element_initialise(struct dom_html_document *doc,
struct dom_html_select_element *ele)
{
ele->form = NULL;
- ele->options = NULL;
return _dom_html_element_initialise(doc, &ele->base,
doc->memoised[hds_SELECT],
@@ -77,9 +76,6 @@ dom_exception _dom_html_select_element_initialise(struct dom_html_document *doc,
*/
void _dom_html_select_element_finalise(struct dom_html_select_element *ele)
{
- if (ele->options != NULL)
- dom_html_options_collection_unref(ele->options);
-
_dom_html_element_finalise(&ele->base);
}
@@ -128,23 +124,17 @@ dom_exception _dom_html_select_element_copy(dom_node_internal *old,
/*-----------------------------------------------------------------------*/
/* Public APIs */
-static dom_exception _dom_html_select_element_ensure_collection(
- dom_html_select_element *ele)
+static dom_exception _dom_html_select_element_make_collection(
+ dom_html_select_element *ele,
+ dom_html_options_collection **col)
{
- dom_exception err;
dom_html_document *doc = (dom_html_document *) dom_node_get_owner(ele);
assert(doc != NULL);
- if (ele->options == NULL) {
- err = _dom_html_options_collection_create(doc,
- (dom_node_internal *) ele,
- is_option, ele, &ele->options);
- if (err != DOM_NO_ERR)
- return err;
- }
-
- return DOM_NO_ERR;
+ return _dom_html_options_collection_create(doc,
+ (dom_node_internal *) ele,
+ is_option, ele, col);
}
/**
@@ -187,33 +177,44 @@ dom_exception dom_html_select_element_get_selected_index(
uint32_t idx, len;
dom_node *option;
bool selected;
+ dom_html_options_collection *col;
+
+ err = _dom_html_select_element_make_collection(ele, &col);
- err = dom_html_select_element_get_length(ele, &len);
- if (err != DOM_NO_ERR)
+ err = dom_html_options_collection_get_length(col, &len);
+ if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
return err;
+ }
for (idx = 0; idx < len; idx++) {
- err = dom_html_options_collection_item(ele->options,
+ err = dom_html_options_collection_item(col,
idx, &option);
- if (err != DOM_NO_ERR)
+ if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
return err;
-
+ }
+
err = dom_html_option_element_get_selected(
(dom_html_option_element *) option, &selected);
dom_node_unref(option);
- if (err != DOM_NO_ERR)
+ if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
return err;
-
+ }
+
if (selected) {
*index = idx;
+ dom_html_options_collection_unref(col);
return DOM_NO_ERR;
}
}
*index = -1;
+ dom_html_options_collection_unref(col);
return DOM_NO_ERR;
}
@@ -248,20 +249,30 @@ dom_exception dom_html_select_element_get_value(
uint32_t idx, len;
dom_node *option;
bool selected;
+ dom_html_options_collection *col;
+
+ err = _dom_html_select_element_make_collection(ele, &col);
+ if (err != DOM_NO_ERR)
+ return err;
err = dom_html_select_element_get_length(ele, &len);
- if (err != DOM_NO_ERR)
+ if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
return err;
+ }
for (idx = 0; idx < len; idx++) {
- err = dom_html_options_collection_item(ele->options,
+ err = dom_html_options_collection_item(col,
idx, &option);
- if (err != DOM_NO_ERR)
+ if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
return err;
+ }
err = dom_html_option_element_get_selected(
(dom_html_option_element *) option, &selected);
if (err != DOM_NO_ERR) {
+ dom_html_options_collection_unref(col);
dom_node_unref(option);
return err;
}
@@ -271,6 +282,7 @@ dom_exception dom_html_select_element_get_value(
(dom_html_option_element *) option,
value);
+ dom_html_options_collection_unref(col);
dom_node_unref(option);
return err;
@@ -278,7 +290,8 @@ dom_exception dom_html_select_element_get_value(
}
*value = NULL;
-
+ dom_html_options_collection_unref(col);
+
return DOM_NO_ERR;
}
@@ -310,12 +323,17 @@ dom_exception dom_html_select_element_get_length(
dom_html_select_element *ele, uint32_t *len)
{
dom_exception err;
-
- err = _dom_html_select_element_ensure_collection(ele);
+ dom_html_options_collection *col;
+
+ err = _dom_html_select_element_make_collection(ele, &col);
if (err != DOM_NO_ERR)
return err;
- return dom_html_options_collection_get_length(ele->options, len);
+ err = dom_html_options_collection_get_length(col, len);
+
+ dom_html_options_collection_unref(col);
+
+ return err;
}
/**
@@ -365,16 +383,7 @@ dom_exception dom__html_select_element_get_options(
dom_html_select_element *ele,
struct dom_html_options_collection **col)
{
- dom_exception err;
-
- err = _dom_html_select_element_ensure_collection(ele);
- if (err != DOM_NO_ERR)
- return err;
-
- dom_html_options_collection_ref(ele->options);
- *col = ele->options;
-
- return DOM_NO_ERR;
+ return _dom_html_select_element_make_collection(ele, col);
}
/**
@@ -540,7 +549,6 @@ dom_exception dom_html_select_element_remove(dom_html_select_element *ele,
{
dom_exception err;
uint32_t len;
- dom_node *option;
err = dom_html_select_element_get_length(ele, &len);
if (err != DOM_NO_ERR)
@@ -550,10 +558,6 @@ dom_exception dom_html_select_element_remove(dom_html_select_element *ele,
if (index < 0 || (uint32_t)index >= len)
return DOM_NO_ERR;
- err = dom_html_options_collection_item(ele->options, index, &option);
- if (err != DOM_NO_ERR)
- return err;
-
/** \todo What does remove mean? Remove option from tree and destroy it? */
return DOM_NOT_SUPPORTED_ERR;
}
diff --git a/src/html/html_select_element.h b/src/html/html_select_element.h
index bd45614..b0eaa91 100644
--- a/src/html/html_select_element.h
+++ b/src/html/html_select_element.h
@@ -20,8 +20,6 @@ struct dom_html_select_element {
/**< The selected element's index */
dom_html_form_element *form;
/**< The form associated with select */
- dom_html_options_collection *options;
- /**< The options objects */
};
/* Create a dom_html_select_element object */