1
0
Fork 0
forked from len0rd/rockbox

Fixed some memory leaks in the theme editor

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26292 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Robert Bieber 2010-05-25 22:24:08 +00:00
parent ff9474e558
commit 0769fc5182
8 changed files with 76 additions and 26 deletions

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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

View file

@ -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);
}

View file

@ -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 */

View file

@ -28,5 +28,4 @@ void skip_whitespace(char** document);
char* scan_string(char** document);
int scan_int(char** document);
#endif // SCANNING_H

View file

@ -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

View file

@ -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