[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Memory leaks at GUIManager (gui_manager.cxx)
From: |
Aggro |
Subject: |
Memory leaks at GUIManager (gui_manager.cxx) |
Date: |
Tue, 11 Apr 2006 16:19:39 -0700 (PDT) |
I tried running pingus on valgrind (open source test
software for example for finding memory leaks), and it
pointed out that at src/gui/gui_manager.cxx
GUIManager::add() leaks memory.
It takes pointers of objects as a parameter, but I
didn't see any code anywhere that would actually
delete those objects. Many parameters are created
using "new", so the GUIManager is AFAIK the only one
holding the actual pointer to the reserved memory.
The add() also takes a second parameter, which should
indicate whether GUIManager should delete the object
or not. Currently the second parameter seems to be
unused.
So, one possibility is to add another vector to
GUIManager, and add all pointers there also, if the
parameter is set to true (GUIManager should delete)
and at the destructor, we loop the elements in this
vector and call delete for all the pointers.
The problem is that if such thing would be done now.
Pingus would crash usually always when closing the
game. Because currently in many places the add()
function is used incorrectly, without the false
parameter, when the object is destroyed by the caller,
and it shouldn't be destroyed by the GUIManager.
( For example: PingusMenu::setup_main_menu() -
gui_manager->add(start_button); ...
PingusMenu::~PingusMenu() - delete start_button; )
My evil plan to go around this problem is to change
the default value for that parameter from true to
false. This way all the function calls which don't
specify this parameter, will work like they used to
work. And only those which specify the parameter will
have their objects deleted (it is currently never
called with the false).
So does anyone know anything about GUIManager or the
reason about why it doesn't delete objects (have I
understood something wrong?) or have any opinions
about the subject. Or should I just try to make the
fix and we will see if it works? This thing affects to
quite many files and it might cause crashing (but
luckily it should crash only at the end of the game if
it does crash. And I should test at least the basic
features before submitting patches.).
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
- Memory leaks at GUIManager (gui_manager.cxx),
Aggro <=