aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-30 22:47:24 +0100
committerMax Kellermann <max@duempel.org>2013-10-30 23:12:45 +0100
commit88e630170ef95f765fdeb95639080052661a1a81 (patch)
tree0ec44b32077a719a1223e2aee21ef229f2817f72
parentda8bdd62c86961a7fb3a72635e05c45203bd8e3c (diff)
downloadmpd-88e630170ef95f765fdeb95639080052661a1a81.tar.gz
mpd-88e630170ef95f765fdeb95639080052661a1a81.tar.xz
mpd-88e630170ef95f765fdeb95639080052661a1a81.zip
mixer/software: fix double free bug
-rw-r--r--src/mixer/SoftwareMixerPlugin.cxx18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/mixer/SoftwareMixerPlugin.cxx b/src/mixer/SoftwareMixerPlugin.cxx
index b7eb8ff0f..193e68f23 100644
--- a/src/mixer/SoftwareMixerPlugin.cxx
+++ b/src/mixer/SoftwareMixerPlugin.cxx
@@ -41,18 +41,28 @@ CreateVolumeFilter()
struct SoftwareMixer final : public Mixer {
Filter *filter;
+ /**
+ * If this is true, then this object "owns" the #Filter
+ * instance (see above). It will be set to false by
+ * software_mixer_get_filter(); after that, the caller will be
+ * responsible for the #Filter.
+ */
+ bool owns_filter;
+
unsigned volume;
SoftwareMixer()
:Mixer(software_mixer_plugin),
- filter(CreateVolumeFilter()),
- volume(100)
+ filter(CreateVolumeFilter()),
+ owns_filter(true),
+ volume(100)
{
assert(filter != nullptr);
}
~SoftwareMixer() {
- delete filter;
+ if (owns_filter)
+ delete filter;
}
};
@@ -115,6 +125,8 @@ software_mixer_get_filter(Mixer *mixer)
{
SoftwareMixer *sm = (SoftwareMixer *)mixer;
assert(sm->IsPlugin(software_mixer_plugin));
+ assert(sm->owns_filter);
+ sm->owns_filter = false;
return sm->filter;
}