summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor
diff options
context:
space:
mode:
authorRobert Bieber <robby@bieberphoto.com>2010-05-25 22:24:08 +0000
committerRobert Bieber <robby@bieberphoto.com>2010-05-25 22:24:08 +0000
commit0769fc5182b211dea276b5895987dfc4bc133995 (patch)
treeaa6c723a2281039637780278d06e168e5852c70e /utils/themeeditor
parentff9474e558a6108a3c9d42260043016ad11971ef (diff)
downloadrockbox-0769fc5182b211dea276b5895987dfc4bc133995.tar.gz
rockbox-0769fc5182b211dea276b5895987dfc4bc133995.zip
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')
-rw-r--r--utils/themeeditor/main.c16
-rw-r--r--utils/themeeditor/main.cpp31
-rw-r--r--utils/themeeditor/skin_debug.h1
-rw-r--r--utils/themeeditor/skin_parser.c36
-rw-r--r--utils/themeeditor/skin_parser.h4
-rw-r--r--utils/themeeditor/skin_scan.h1
-rw-r--r--utils/themeeditor/tag_table.h8
-rw-r--r--utils/themeeditor/themeeditor.pro5
8 files changed, 76 insertions, 26 deletions
diff --git a/utils/themeeditor/main.c b/utils/themeeditor/main.c
deleted file mode 100644
index 269cad7840..0000000000
--- a/utils/themeeditor/main.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "skin_parser.h"
-#include "skin_debug.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-
-int main(int argc, char* argv[])
-{
- char* doc = "%Vd(U))\n\n%?bl(test,3,5,2,1)<param2|param3>";
-
- struct skin_element* test = skin_parse(doc);
-
- skin_debug_tree(test);
-
- return 0;
-}
diff --git a/utils/themeeditor/main.cpp b/utils/themeeditor/main.cpp
new file mode 100644
index 0000000000..3d7a01e7f2
--- /dev/null
+++ b/utils/themeeditor/main.cpp
@@ -0,0 +1,31 @@
+namespace wps
+{
+ extern "C"
+ {
+#include "skin_parser.h"
+#include "skin_debug.h"
+ }
+}
+
+#include <cstdlib>
+#include <cstdio>
+
+#include <QtGui/QApplication>
+#include <QFileSystemModel>
+#include <QTreeView>
+
+int main(int argc, char* argv[])
+{
+
+ char* doc = "%Vd(U)\n\n%?bl(test,3,5,2,1)<param2|param3>";
+
+ struct wps::skin_element* test = wps::skin_parse(doc);
+
+ wps::skin_debug_tree(test);
+
+ wps::skin_free_tree(test);
+
+
+ return 0;
+}
+
diff --git a/utils/themeeditor/skin_debug.h b/utils/themeeditor/skin_debug.h
index e5bac1ede1..c100eb1d2e 100644
--- a/utils/themeeditor/skin_debug.h
+++ b/utils/themeeditor/skin_debug.h
@@ -33,5 +33,4 @@ void skin_debug_tree(struct skin_element* root);
void skin_debug_params(int count, struct skin_tag_parameter params[]);
void skin_debug_indent();
-
#endif // SKIN_DEBUG_H
diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c
index bc1f2a5ed2..dd061a1ac9 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);
+}
diff --git a/utils/themeeditor/skin_parser.h b/utils/themeeditor/skin_parser.h
index a6fd1aa206..50980023b5 100644
--- a/utils/themeeditor/skin_parser.h
+++ b/utils/themeeditor/skin_parser.h
@@ -93,7 +93,7 @@ struct skin_element
char* text;
/* The tag or conditional name */
- char* name;
+ char name[3];
/* Pointer to and size of an array of parameters */
int params_count;
@@ -121,4 +121,6 @@ struct skin_element** skin_alloc_children(int count);
struct skin_tag_parameter* skin_alloc_params(int count);
char* skin_alloc_string(int length);
+void skin_free_tree(struct skin_element* root);
+
#endif /* GENERIC_PARSER_H */
diff --git a/utils/themeeditor/skin_scan.h b/utils/themeeditor/skin_scan.h
index 863e9b7d64..210f39cdfd 100644
--- a/utils/themeeditor/skin_scan.h
+++ b/utils/themeeditor/skin_scan.h
@@ -28,5 +28,4 @@ void skip_whitespace(char** document);
char* scan_string(char** document);
int scan_int(char** document);
-
#endif // SCANNING_H
diff --git a/utils/themeeditor/tag_table.h b/utils/themeeditor/tag_table.h
index 807d3e15ac..0fde717f11 100644
--- a/utils/themeeditor/tag_table.h
+++ b/utils/themeeditor/tag_table.h
@@ -22,6 +22,14 @@
#ifndef TAG_TABLE_H
#define TAG_TABLE_H
+#ifdef __cplusplus
+extern "C"
+{
+namespace wps
+{
+#endif
+
+
/*
* Struct for tag parsing information
* name - The name of the tag, i.e. V for %V
diff --git a/utils/themeeditor/themeeditor.pro b/utils/themeeditor/themeeditor.pro
index 14b001db12..f3ce7f6810 100644
--- a/utils/themeeditor/themeeditor.pro
+++ b/utils/themeeditor/themeeditor.pro
@@ -1,10 +1,11 @@
+CONFIG += qt
HEADERS += tag_table.h \
symbols.h \
skin_parser.h \
skin_scan.h \
skin_debug.h
SOURCES += tag_table.c \
- main.c \
skin_parser.c \
skin_scan.c \
- skin_debug.c
+ skin_debug.c \
+ main.cpp