diff options
| author | Robert Bieber <robby@bieberphoto.com> | 2010-05-25 22:24:08 +0000 |
|---|---|---|
| committer | Robert Bieber <robby@bieberphoto.com> | 2010-05-25 22:24:08 +0000 |
| commit | 0769fc5182b211dea276b5895987dfc4bc133995 (patch) | |
| tree | aa6c723a2281039637780278d06e168e5852c70e /utils/themeeditor/skin_parser.c | |
| parent | ff9474e558a6108a3c9d42260043016ad11971ef (diff) | |
| download | rockbox-0769fc5182b211dea276b5895987dfc4bc133995.zip rockbox-0769fc5182b211dea276b5895987dfc4bc133995.tar.gz rockbox-0769fc5182b211dea276b5895987dfc4bc133995.tar.bz2 rockbox-0769fc5182b211dea276b5895987dfc4bc133995.tar.xz | |
Fixed some memory leaks in the theme editor
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26292 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/themeeditor/skin_parser.c')
| -rw-r--r-- | utils/themeeditor/skin_parser.c | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c index bc1f2a5..dd061a1 100644 --- a/utils/themeeditor/skin_parser.c +++ b/utils/themeeditor/skin_parser.c @@ -32,7 +32,7 @@ /* Declaration of parse tree buffer */ char skin_parse_tree[SKIN_MAX_MEMORY]; -int skin_current_block = 0; +int skin_current_block = 0; /* Global variables for the parser */ int skin_line = 0; @@ -330,7 +330,6 @@ int skin_parse_tag(struct skin_element* element, char** document) /* Copying basic tag info */ element->type = TAG; - element->name = skin_alloc_string(strlen(tag_name)); strcpy(element->name, tag_name); element->line = skin_line; @@ -641,9 +640,6 @@ int skin_parse_newline(struct skin_element* element, char** document) element->type = NEWLINE; element->line = skin_line; skin_line++; - element->text = skin_alloc_string(1); - element->text[0] = '\n'; - element->text[1] = '\0'; element->next = NULL; *document = cursor; @@ -801,3 +797,33 @@ struct skin_element** skin_alloc_children(int count) { return (struct skin_element**) malloc(sizeof(struct skin_element*) * count); } + +void skin_free_tree(struct skin_element* root) +{ + int i; + + /* First make the recursive call */ + if(!root) + return; + skin_free_tree(root->next); + + /* Free any text */ + if(root->type == TEXT) + free(root->text); + + /* Then recursively free any children, before freeing their pointers */ + for(i = 0; i < root->children_count; i++) + skin_free_tree(root->children[i]); + if(root->children_count > 0) + free(root->children); + + /* Free any parameters, making sure to deallocate strings */ + for(i = 0; i < root->params_count; i++) + if(root->params[i].type == STRING) + free(root->params[i].data.text); + if(root->params_count > 0) + free(root->params); + + /* Finally, delete root's memory */ + free(root); +} |