From 0e9168b5560b47d92a80b8f5fda9a109947b5ce7 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Mon, 30 Jan 2006 19:37:49 +0000 Subject: [PATCH] Fix some memory leaks. Fix double destruction of classes. Add some input checks on the environment reader Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2465 --- include/setup.h | 12 ++++++------ src/misc/setup.cpp | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/setup.h b/include/setup.h index 4313bf4b..e65ef854 100644 --- a/include/setup.h +++ b/include/setup.h @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: setup.h,v 1.20 2005-04-21 19:53:40 qbix79 Exp $ */ +/* $Id: setup.h,v 1.21 2006-01-30 19:37:48 qbix79 Exp $ */ #ifndef DOSBOX_SETUP_H #define DOSBOX_SETUP_H @@ -139,7 +139,7 @@ private: std::list destroyfunctions; std::string sectionname; public: - Section(const char* _sectionname) { sectionname=_sectionname; } + Section(const char* _sectionname):sectionname(_sectionname) { } void AddInitFunction(SectionFunction func,bool canchange=false) {initfunctions.push_back(Function_wrapper(func,canchange));} void AddDestroyFunction(SectionFunction func,bool canchange=false) {destroyfunctions.push_front(Function_wrapper(func,canchange));} @@ -148,9 +148,9 @@ public: const char* GetName() {return sectionname.c_str();} virtual char* GetPropValue(const char* _property)=0; - virtual void HandleInputline(char * _line){} - virtual void PrintData(FILE* outfile) {} - virtual ~Section(){ExecuteDestroy(true); } + virtual void HandleInputline(char * _line)=0; + virtual void PrintData(FILE* outfile)=0; + virtual ~Section() { /*Children must call executedestroy ! */} }; @@ -175,7 +175,7 @@ public: void PrintData(FILE* outfile); virtual char* GetPropValue(const char* _property); //ExecuteDestroy should be here else the destroy functions use destroyed properties - virtual ~Section_prop(){ExecuteDestroy(true);} + virtual ~Section_prop(); }; class Section_line: public Section{ diff --git a/src/misc/setup.cpp b/src/misc/setup.cpp index 911e040f..2c0fb772 100644 --- a/src/misc/setup.cpp +++ b/src/misc/setup.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: setup.cpp,v 1.31 2005-07-24 19:04:11 qbix79 Exp $ */ +/* $Id: setup.cpp,v 1.32 2006-01-30 19:37:49 qbix79 Exp $ */ #include "dosbox.h" #include "cross.h" @@ -229,6 +229,15 @@ Section_prop* Config::AddSection_prop(const char* _name,void (*_initfunction)(Se return blah; } +Section_prop::~Section_prop() { +//ExecuteDestroy should be here else the destroy functions use destroyed properties + ExecuteDestroy(true); + /* Delete properties themself (properties stores the pointer of a prop */ + for(it prop = properties.begin(); prop != properties.end(); prop++) + delete (*prop); +} + + Section_line* Config::AddSection_line(const char* _name,void (*_initfunction)(Section*)){ Section_line* blah = new Section_line(_name); blah->AddInitFunction(_initfunction); @@ -341,10 +350,14 @@ void Config::ParseEnv(char ** envp) { if(strncasecmp(copy,"DOSBOX_",7)) continue; char* sec_name = ©[7]; + if(!(*sec_name)) + continue; char* prop_name = strrchr(sec_name,'_'); + if(!prop_name || !(*prop_name)) + continue; *prop_name++=0; Section* sect = GetSection(sec_name); - if(!sect) + if(!sect) continue; sect->HandleInputline(prop_name); }