Commit 9a6612c6 authored by Dick Hollenbeck's avatar Dick Hollenbeck

use a block scope to invoke wxFFile's destructor before renaming temporary file

parent f3e17179
...@@ -3933,23 +3933,30 @@ void FPL_CACHE::Save() ...@@ -3933,23 +3933,30 @@ void FPL_CACHE::Save()
wxString tempFileName = wxFileName::CreateTempFileName( m_lib_name ); wxString tempFileName = wxFileName::CreateTempFileName( m_lib_name );
wxLogDebug( "tempFileName:'%s'\n", TO_UTF8( tempFileName ) ); // wxLogDebug( "tempFileName:'%s'\n", TO_UTF8( tempFileName ) );
FILE* fp = wxFopen( tempFileName, wxT( "w" ) ); // a block {} scope to fire wxFFile wxf()'s destructor
if( !fp )
{ {
THROW_IO_ERROR( wxString::Format( FILE* fp = wxFopen( tempFileName, wxT( "w" ) );
_( "Unable to open or create legacy library file '%s'" ), if( !fp )
m_lib_name.GetData() ) ); {
} THROW_IO_ERROR( wxString::Format(
_( "Unable to open or create legacy library file '%s'" ),
m_lib_name.GetData() ) );
}
// wxf now owns fp, will close on exception or return // wxf now owns fp, will close on exception or exit from
wxFFile wxf( fp ); // this block {} scope
wxFFile wxf( fp );
SaveHeader( fp );
SaveIndex( fp );
SaveModules( fp );
SaveEndOfFile( fp );
}
SaveHeader( fp ); // fp is now closed here, and that seems proper before trying to rename
SaveIndex( fp ); // the temporary file to m_lib_name.
SaveModules( fp );
SaveEndOfFile( fp );
wxRemove( m_lib_name ); // it is not an error if this does not exist wxRemove( m_lib_name ); // it is not an error if this does not exist
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment