Skip to content

Commit

Permalink
Fix crash due to fftw_lock being used after deleted by the destructor
Browse files Browse the repository at this point in the history
Proper fix would be to figure out why alloc/free_channel_data is still
getting called during destruction, but this should work as well.

Fixes #12
  • Loading branch information
sjohannes committed Aug 31, 2020
1 parent 3430c54 commit f9b00a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
12 changes: 6 additions & 6 deletions gst/moodbar/gstfastspectrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ enum {
PROP_BANDS
};

// Static lock for creating & destroying FFTW plans.
// Moved outside GstFastSpectrumClass due to https://github.com/exaile/moodbar/issues/12
static std::mutex fftw_lock;

#define gst_fastspectrum_parent_class parent_class
G_DEFINE_TYPE (GstFastSpectrum, gst_fastspectrum, GST_TYPE_AUDIO_FILTER);

Expand Down Expand Up @@ -136,10 +140,8 @@ gst_fastspectrum_alloc_channel_data (GstFastSpectrum * spectrum)

spectrum->spect_magnitude = new double[bands]{};

GstFastSpectrumClass* klass = reinterpret_cast<GstFastSpectrumClass*>(
G_OBJECT_GET_CLASS(spectrum));
{
std::lock_guard<decltype(klass->fftw_lock)> l(klass->fftw_lock);
std::lock_guard<decltype(fftw_lock)> l(fftw_lock);
spectrum->plan = fftw_plan_dft_r2c_1d(
nfft,
spectrum->fft_input,
Expand All @@ -152,11 +154,9 @@ gst_fastspectrum_alloc_channel_data (GstFastSpectrum * spectrum)
static void
gst_fastspectrum_free_channel_data (GstFastSpectrum * spectrum)
{
GstFastSpectrumClass* klass = reinterpret_cast<GstFastSpectrumClass*>(
G_OBJECT_GET_CLASS(spectrum));
if (spectrum->channel_data_initialised) {
{
std::lock_guard<decltype(klass->fftw_lock)> l(klass->fftw_lock);
std::lock_guard<decltype(fftw_lock)> l(fftw_lock);
fftw_destroy_plan(spectrum->plan);
}
fftw_free(spectrum->fft_input);
Expand Down
3 changes: 0 additions & 3 deletions gst/moodbar/gstfastspectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ struct GstFastSpectrum {

struct GstFastSpectrumClass {
GstAudioFilterClass parent_class;

// Static lock for creating & destroying FFTW plans.
std::mutex fftw_lock;
};

GType gst_fastspectrum_get_type (void);
Expand Down

0 comments on commit f9b00a9

Please sign in to comment.