diff options
| author | Matthias Melcher <fltk@matthiasm.com> | 2007-02-23 15:37:53 +0000 |
|---|---|---|
| committer | Matthias Melcher <fltk@matthiasm.com> | 2007-02-23 15:37:53 +0000 |
| commit | 7696c64a46de8780d3f9eda655a94b37cc3caf00 (patch) | |
| tree | d722810701befdb7a0d3393ee7329f6f1b2009df | |
| parent | 769c6a8e5027a1b89901769fa16b07195d1b1401 (diff) | |
Setting pointers in Fl_Preferences-destructor to zero. This should not be needed, but may help Cygwin figure it out correctly. I re-tested in Valgrind, and no members of deleted groups are ever accessed, just as I said. There is a slight p[ossibility of such false access if a C++ compiler does not conform to the standard and calls destructors in the fasle order.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@5710 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | src/Fl_Preferences.cxx | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/src/Fl_Preferences.cxx b/src/Fl_Preferences.cxx index 8b069efab..5f70d0711 100644 --- a/src/Fl_Preferences.cxx +++ b/src/Fl_Preferences.cxx @@ -118,6 +118,10 @@ Fl_Preferences::~Fl_Preferences() { if (!node->parent()) delete rootNode; // DO NOT delete nodes! The root node will do that after writing the preferences + // zero all pointer to avoid memory errors, event though + // Valgrind does not complain (Cygwind does though) + node = 0L; + rootNode = 0L; } @@ -573,7 +577,10 @@ Fl_Preferences::Name::Name( const char *format, ... ) // delete the name Fl_Preferences::Name::~Name() { - free(data_); + if (data_) { + free(data_); + data_ = 0L; + } } //----------------------------------------------------------------------------- @@ -737,13 +744,20 @@ Fl_Preferences::RootNode::~RootNode() { if ( prefs_->node->dirty() ) write(); - if ( filename_ ) + if ( filename_ ) { free( filename_ ); - if ( vendor_ ) + filename_ = 0L; + } + if ( vendor_ ) { free( vendor_ ); - if ( application_ ) + vendor_ = 0L; + } + if ( application_ ) { free( application_ ); + application_ = 0L; + } delete prefs_->node; + prefs_ = 0L; } // read a preferences file and construct the group tree and with all entry leafs @@ -837,19 +851,30 @@ Fl_Preferences::Node::~Node() nx = nd->next_; delete nd; } + child_ = 0L; if ( entry ) { for ( int i = 0; i < nEntry; i++ ) { - if ( entry[i].name ) + if ( entry[i].name ) { free( entry[i].name ); - if ( entry[i].value ) + entry[i].name = 0L; + } + if ( entry[i].value ) { free( entry[i].value ); + entry[i].value = 0L; + } } free( entry ); + entry = 0L; + nEntry = 0; } - if ( path_ ) + if ( path_ ) { free( path_ ); + path_ = 0L; + } + next_ = 0L; + parent_ = 0L; } // recursively check if any entry is dirty (was changed after loading a fresh prefs file) |
