Update of /cvsroot/audacity/audacity-src/src In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv19055/src
Modified Files: PluginManager.cpp Log Message: Fixed attempt to close non-open file. Also avoid memory leak when config not writable (but no reporting of the error still). Index: PluginManager.cpp =================================================================== RCS file: /cvsroot/audacity/audacity-src/src/PluginManager.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- PluginManager.cpp 3 Aug 2009 17:14:20 -0000 1.1 +++ PluginManager.cpp 8 Nov 2009 11:07:11 -0000 1.2 @@ -60,44 +60,56 @@ void PluginManager::Open() { + // Writes out any pending changes and + // sets mConfig == NULL. Close(); wxFileName name(FileNames::PluginsCache()); - wxFile file; if (!::wxFileExists(FileNames::PluginsCache())) { + wxFile file; file.Create(FileNames::PluginsCache()); file.Close(); } wxFileInputStream stream(FileNames::PluginsCache()); + // mConfig is NULL because of the PlugInManager::Close() earlier. + // create it and fill it from the stream. mConfig = new wxFileConfig(stream); - - file.Close(); } void PluginManager::Close() { - if (mConfig && IsDirty()) { + // IF already closed THEN nothing to do. + if( mConfig == NULL ) + return; + // JKC: There is no recovery action here if writing the + // config out fails (e.g. due to write protected media). + // I guess we can live with that for now. + // This function will still close the config and + // delete it, without updating the file. + if( IsDirty()) + { wxFile file(FileNames::PluginsCache(), wxFile::write); - if (!file.IsOpened()) { + if (file.IsOpened()) + { + // Might fail to open... wxLogDebug(wxT("Couldn't open plugins cache for write")); - return; } - - wxFileOutputStream stream(file); - - SetDirty(!mConfig->Save(stream)); - - file.Close(); + else + { + wxFileOutputStream stream(file); + // Save() might return false. + mConfig->Save(stream); + file.Close(); + } } - if (mConfig && !IsDirty()) { - delete mConfig; - mConfig = NULL; - } + SetDirty( false ); + delete mConfig; + mConfig = NULL; } bool PluginManager::IsDirty() ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Audacity-cvs mailing list Audacity-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/audacity-cvs