summaryrefslogtreecommitdiff
path: root/desktop/tree.c
diff options
context:
space:
mode:
authorVincent Sanders <vince@netsurf-browser.org>2013-05-03 21:17:11 +0100
committerVincent Sanders <vince@netsurf-browser.org>2013-05-03 21:17:11 +0100
commit5c57a30047b4c9330110e5de9f5f406571f9baf1 (patch)
tree019aa80504701b34e2cca51913c5625c0999b6fc /desktop/tree.c
parent6c7ca26bdc88ac95feb53b647c1c3b33f602f04c (diff)
downloadnetsurf-5c57a30047b4c9330110e5de9f5f406571f9baf1.tar.gz
netsurf-5c57a30047b4c9330110e5de9f5f406571f9baf1.tar.bz2
cleanup title string ownership madness in the tree_create_folder_node() API
Diffstat (limited to 'desktop/tree.c')
-rw-r--r--desktop/tree.c38
1 files changed, 12 insertions, 26 deletions
diff --git a/desktop/tree.c b/desktop/tree.c
index af64be83b..e72ef6001 100644
--- a/desktop/tree.c
+++ b/desktop/tree.c
@@ -233,26 +233,19 @@ struct tree *tree_create(unsigned int flags,
const struct treeview_table *callbacks, void *client_data)
{
struct tree *tree;
- char *title;
tree = calloc(sizeof(struct tree), 1);
if (tree == NULL) {
LOG(("calloc failed"));
- warn_user("NoMemory", 0);
+ warn_user(messages_get_errorcode(NSERROR_NOMEM), 0);
return NULL;
}
- title = strdup("Root");
- if (title == NULL) {
- LOG(("malloc failed"));
- warn_user("NoMemory", 0);
- free(tree);
- return NULL;
- }
- tree->root = tree_create_folder_node(NULL, NULL, title,
+ tree->root = tree_create_folder_node(NULL,
+ NULL,
+ messages_get("Root"),
false, false, false);
if (tree->root == NULL) {
- free(title);
free(tree);
return NULL;
}
@@ -553,18 +546,7 @@ static void tree_recalculate_node_sizes(struct tree *tree, struct node *node,
}
-/**
- * Creates a folder node with the specified title, and optionally links it into
- * the tree.
- *
- * \param tree the owner tree of 'parent', may be NULL
- * \param parent the parent node, or NULL not to link
- * \param title the node title (not copied, used directly)
- * \param editable if true, the node title will be editable
- * \param retain_in_memory if true, the node will stay in memory after deletion
- * \param deleted if true, the node is created with the deleted flag
- * \return the newly created node.
- */
+/* exported interface documented in desktop/tree.h */
struct node *tree_create_folder_node(struct tree *tree, struct node *parent,
const char *title, bool editable, bool retain_in_memory,
bool deleted)
@@ -575,16 +557,20 @@ struct node *tree_create_folder_node(struct tree *tree, struct node *parent,
node = calloc(sizeof(struct node), 1);
if (node == NULL) {
- LOG(("calloc failed"));
- warn_user("NoMemory", 0);
return NULL;
}
+
+ node->data.text = strdup(title);
+ if (node->data.text == NULL) {
+ free(node);
+ return NULL;
+ }
+
node->folder = true;
node->retain_in_memory = retain_in_memory;
node->deleted = deleted;
node->data.parent = node;
node->data.type = NODE_ELEMENT_TEXT;
- node->data.text = title;
node->data.flag = TREE_ELEMENT_TITLE;
node->data.editable = editable;
node->sort = NULL;