Skip to content

Commit

Permalink
Don't use VST-provided memory when loading chunks (#3805)
Browse files Browse the repository at this point in the history
  • Loading branch information
DomClark authored and Umcaruje committed Sep 20, 2017
1 parent 8a39302 commit fb5a58a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
1 change: 1 addition & 0 deletions include/aeffectx.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const int effEditOpen = 14;
const int effEditClose = 15;
const int effEditIdle = 19;
const int effEditTop = 20;
const int effSetChunk = 24;
const int effProcessEvents = 25;
const int effGetEffectName = 45;
const int effGetVendorString = 47;
Expand Down
20 changes: 4 additions & 16 deletions plugins/vst_base/RemoteVstPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,30 +1385,18 @@ void RemoteVstPlugin::loadPresetFile( const std::string & _file )

void RemoteVstPlugin::loadChunkFromFile( const std::string & _file, int _len )
{
char * buf = NULL;

void * chunk = NULL;
// various plugins need this in order to not crash when setting
// chunk (also we let the plugin allocate "safe" memory this way)
const int actualLen = pluginDispatch( 23, 0, 0, &chunk );

// allocated buffer big enough?
if( _len > actualLen )
{
// no, then manually allocate a buffer
buf = new char[_len];
chunk = buf;
}
char * chunk = new char[_len];

const int fd = open( _file.c_str(), O_RDONLY | O_BINARY );
if ( ::read( fd, chunk, _len ) != _len )
{
fprintf( stderr, "Error loading chunk from file.\n" );
}
close( fd );
pluginDispatch( 24, 0, _len, chunk );

delete[] buf;
pluginDispatch( effSetChunk, 0, _len, chunk );

delete[] chunk;
}


Expand Down

0 comments on commit fb5a58a

Please sign in to comment.