Skip to content

Commit

Permalink
fix #202751 SegFault delete SFont while loadSamples()
Browse files Browse the repository at this point in the history
Mutex may be locked if another thread is trying to load, add, or delete soundfonts.

If another thread deletes a soundfont, trying to read the zone info will result in a SEGFAULT as described in issue #202751.

These operations need to be mutually-exclusive, but since Seq::process() is a realtime context, we can't block here.

In order to keep Seq::process() running, my solution here is to simply not execute the rest of loadSamples() if another thread had locked that mutex.
  • Loading branch information
Eric Fontaine committed May 19, 2017
1 parent 4d5cd90 commit af724bd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fluid/sfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ Preset::~Preset()

void Preset::loadSamples()
{
// sfont->synth->mutex.lock();
if (!sfont->synth->mutex.tryLock())
return;

if (_global_zone && _global_zone->instrument) {
Instrument* i = _global_zone->instrument;
if (i->global_zone && i->global_zone->sample)
Expand All @@ -153,7 +155,8 @@ void Preset::loadSamples()
foreach(Zone* iz, i->zones)
iz->sample->load();
}
// sfont->synth->mutex.unlock();

sfont->synth->mutex.unlock();
}

//---------------------------------------------------------
Expand Down

1 comment on commit af724bd

@ericfont
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for anyone looking at this, this was a failed attempt, and causes problems down the line...

Please sign in to comment.