Fix some memory leaks

This commit is contained in:
simon.kagstrom 2010-01-23 16:34:58 +00:00
parent 17e7d64804
commit b7c9a8c4df
5 changed files with 15 additions and 1 deletions

View File

@ -112,6 +112,9 @@ Gui::~Gui()
delete this->cur_gameInfo; delete this->cur_gameInfo;
delete this->timerController; delete this->timerController;
if (this->status_bar)
delete this->status_bar;
if (this->dlg) if (this->dlg)
delete this->dlg; delete this->dlg;
@ -132,6 +135,7 @@ Gui::~Gui()
SDL_FreeSurface(this->textbox); SDL_FreeSurface(this->textbox);
SDL_FreeSurface(this->selected_key); SDL_FreeSurface(this->selected_key);
SDL_FreeSurface(this->highlighted_key); SDL_FreeSurface(this->highlighted_key);
SDL_FreeSurface(this->status_bar_bg);
if (this->default_font) if (this->default_font)
delete this->default_font; delete this->default_font;
@ -187,6 +191,7 @@ bool Gui::setTheme(const char *path)
SDL_FreeSurface(this->textbox); SDL_FreeSurface(this->textbox);
SDL_FreeSurface(this->selected_key); SDL_FreeSurface(this->selected_key);
SDL_FreeSurface(this->highlighted_key); SDL_FreeSurface(this->highlighted_key);
SDL_FreeSurface(this->status_bar_bg);
if (this->default_font) if (this->default_font)
delete this->default_font; delete this->default_font;

View File

@ -366,6 +366,8 @@ void Menu::setTextColor(SDL_Color clr)
Menu::~Menu() Menu::~Menu()
{ {
for (int i = 0; i < this->n_entries; i++)
free((void*)this->pp_msgs[i]);
free(this->pp_msgs); free(this->pp_msgs);
free(this->p_submenus); free(this->p_submenus);
} }

View File

@ -12,13 +12,14 @@ TTF_Font *read_and_alloc_font(const char *path, int pt_size)
{ {
TTF_Font *out; TTF_Font *out;
SDL_RWops *rw; SDL_RWops *rw;
Uint8 *data = (Uint8*)xmalloc(1 * 1024*1024); Uint8 *data;
FILE *fp = fopen(path, "r"); FILE *fp = fopen(path, "r");
if (!fp) { if (!fp) {
fprintf(stderr, "Could not open font %s\n", path); fprintf(stderr, "Could not open font %s\n", path);
return NULL; return NULL;
} }
data = (Uint8*)xmalloc(1 * 1024*1024);
fread(data, 1, 1 * 1024 * 1024, fp); fread(data, 1, 1 * 1024 * 1024, fp);
rw = SDL_RWFromMem(data, 1 * 1024 * 1024); rw = SDL_RWFromMem(data, 1 * 1024 * 1024);
if (!rw) if (!rw)

View File

@ -92,6 +92,11 @@ VirtualKeyboard::VirtualKeyboard(Font *font) : GuiView(), ListenerManager()
memset(this->buf, 0, sizeof(struct virtkey) * this->buf_len); memset(this->buf, 0, sizeof(struct virtkey) * this->buf_len);
} }
VirtualKeyboard::~VirtualKeyboard()
{
free(this->buf);
}
void VirtualKeyboard::draw(SDL_Surface *where, int x_base, int y_base, int w, int h) void VirtualKeyboard::draw(SDL_Surface *where, int x_base, int y_base, int w, int h)
{ {
int key_w = w / KEY_COLS; int key_w = w / KEY_COLS;

View File

@ -40,6 +40,7 @@ class VirtualKeyboard : public GuiView, public ListenerManager
{ {
public: public:
VirtualKeyboard(Font *font); VirtualKeyboard(Font *font);
~VirtualKeyboard();
/* Conversions */ /* Conversions */
const char *keycodeToString(int kc); const char *keycodeToString(int kc);