RemoteVstPlugin: fix crashes when failed to open a file (#5235)
This commit is contained in:
@@ -718,6 +718,7 @@ void RemoteVstPlugin::init( const std::string & _plugin_file )
|
||||
|
||||
static void close_check( FILE* fp )
|
||||
{
|
||||
if (!fp) {return;}
|
||||
if( fclose( fp ) )
|
||||
{
|
||||
perror( "close" );
|
||||
@@ -1115,6 +1116,12 @@ void RemoteVstPlugin::saveChunkToFile( const std::string & _file )
|
||||
if( len > 0 )
|
||||
{
|
||||
FILE* fp = F_OPEN_UTF8( _file, "wb" );
|
||||
if (!fp)
|
||||
{
|
||||
fprintf( stderr,
|
||||
"Error opening file for saving chunk.\n" );
|
||||
return;
|
||||
}
|
||||
if ( fwrite( chunk, 1, len, fp ) != len )
|
||||
{
|
||||
fprintf( stderr,
|
||||
@@ -1280,6 +1287,12 @@ void RemoteVstPlugin::savePreset( const std::string & _file )
|
||||
pBank->numPrograms = endian_swap( uIntToFile );
|
||||
|
||||
FILE * stream = F_OPEN_UTF8( _file, "w" );
|
||||
if (!stream)
|
||||
{
|
||||
fprintf( stderr,
|
||||
"Error opening file for saving preset.\n" );
|
||||
return;
|
||||
}
|
||||
fwrite ( pBank, 1, 28, stream );
|
||||
fwrite ( progName, 1, isPreset ? 28 : 128, stream );
|
||||
if ( chunky ) {
|
||||
@@ -1332,6 +1345,12 @@ void RemoteVstPlugin::loadPresetFile( const std::string & _file )
|
||||
unsigned int len = 0;
|
||||
sBank * pBank = (sBank*) new char[ sizeof( sBank ) ];
|
||||
FILE * stream = F_OPEN_UTF8( _file, "r" );
|
||||
if (!stream)
|
||||
{
|
||||
fprintf( stderr,
|
||||
"Error opening file for loading preset.\n" );
|
||||
return;
|
||||
}
|
||||
if ( fread ( pBank, 1, 56, stream ) != 56 )
|
||||
{
|
||||
fprintf( stderr, "Error loading preset file.\n" );
|
||||
@@ -1433,6 +1452,12 @@ void RemoteVstPlugin::loadChunkFromFile( const std::string & _file, int _len )
|
||||
char * chunk = new char[_len];
|
||||
|
||||
FILE* fp = F_OPEN_UTF8( _file, "rb" );
|
||||
if (!fp)
|
||||
{
|
||||
fprintf( stderr,
|
||||
"Error opening file for loading chunk.\n" );
|
||||
return;
|
||||
}
|
||||
if ( fread( chunk, 1, _len, fp ) != _len )
|
||||
{
|
||||
fprintf( stderr, "Error loading chunk from file.\n" );
|
||||
|
||||
Reference in New Issue
Block a user