mail[Wesnoth-commits] r28584 - in /trunk/src/gui/widgets: settings.cpp settings.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by koraq on August 14, 2008 - 18:56:
Author: mordante
Date: Thu Aug 14 18:26:05 2008
New Revision: 28584

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28584&view=rev
Log:
Valgrid discovered some memory leaks.  The reference_counted objects aren't
stored in a intrusive_ptr so don't cleanup themselves.

This commit fixes tcontrol_definition and adds an extra assert to avoid a 
leak.

Modified:
    trunk/src/gui/widgets/settings.cpp
    trunk/src/gui/widgets/settings.hpp

Modified: trunk/src/gui/widgets/settings.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.cpp?rev=28584&r1=28583&r2=28584&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.cpp (original)
+++ trunk/src/gui/widgets/settings.cpp Thu Aug 14 18:26:05 2008
@@ -308,6 +308,10 @@
 
                T* def = new T(**itor);
 
+               // We assume all definitions are unique if not we would leak 
memory.
+               assert(control_definition[definition_type].find(def->id) 
+                       == control_definition[definition_type].end());
+
                
control_definition[definition_type].insert(std::make_pair(def->id, def));
        }
 
@@ -1071,7 +1075,7 @@
 
        assert(control_definition != 
current_gui->second.control_definition.end());
 
-       std::map<std::string, tcontrol_definition*>::const_iterator 
+       std::map<std::string, tcontrol_definition_ptr>::const_iterator 
                control = control_definition->second.find(definition);
 
        if(control == control_definition->second.end()) {

Modified: trunk/src/gui/widgets/settings.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/settings.hpp?rev=28584&r1=28583&r2=28584&view=diff
==============================================================================
--- trunk/src/gui/widgets/settings.hpp (original)
+++ trunk/src/gui/widgets/settings.hpp Thu Aug 14 18:26:05 2008
@@ -123,6 +123,8 @@
 
 };
 
+typedef boost::intrusive_ptr<tcontrol_definition> tcontrol_definition_ptr;
+
 struct tbutton_definition : public tcontrol_definition
 {
        tbutton_definition(const config& cfg);
@@ -325,7 +327,7 @@
        void activate() const;
        
        typedef std::map <std::string /*control type*/, 
-               std::map<std::string /*id*/, tcontrol_definition*> > 
+               std::map<std::string /*id*/, tcontrol_definition_ptr> > 
                tcontrol_definition_map;
 
        tcontrol_definition_map control_definition;




Related Messages


Powered by MHonArc, Updated Thu Aug 14 19:02:50 2008