Permalink
Browse files

Fixing use-after-free resulting in heap corruption

1 parent 45858cf commit 23490a09549bd3170512531254edb59ef20e0263 Eoin Mcloughlin committed Oct 9, 2016
Showing with 22 additions and 24 deletions.
  1. +1 −1 amplitudedemod.cpp
  2. +1 −1 amplitudedemod.h
  3. +1 −1 frequencydemod.cpp
  4. +1 −1 frequencydemod.h
  5. +10 −12 plots.cpp
  6. +1 −1 samplebuffer.cpp
  7. +2 −2 samplebuffer.h
  8. +1 −1 spectrogramplot.cpp
  9. +1 −1 threshold.cpp
  10. +1 −1 threshold.h
  11. +1 −1 tunertransform.cpp
  12. +1 −1 tunertransform.h
View
@@ -19,7 +19,7 @@
#include "amplitudedemod.h"
-AmplitudeDemod::AmplitudeDemod(SampleSource<std::complex<float>> *src) : SampleBuffer(src)
+AmplitudeDemod::AmplitudeDemod(std::shared_ptr<SampleSource<std::complex<float>>> src) : SampleBuffer(src)
{
}
View
@@ -24,6 +24,6 @@
class AmplitudeDemod : public SampleBuffer<std::complex<float>, float>
{
public:
- AmplitudeDemod(SampleSource<std::complex<float>> *src);
+ AmplitudeDemod(std::shared_ptr<SampleSource<std::complex<float>>> src);
void work(void *input, void *output, int count, off_t sampleid) override;
};
View
@@ -21,7 +21,7 @@
#include <liquid/liquid.h>
#include "util.h"
-FrequencyDemod::FrequencyDemod(SampleSource<std::complex<float>> *src) : SampleBuffer(src)
+FrequencyDemod::FrequencyDemod(std::shared_ptr<SampleSource<std::complex<float>>> src) : SampleBuffer(src)
{
}
View
@@ -24,6 +24,6 @@
class FrequencyDemod : public SampleBuffer<std::complex<float>, float>
{
public:
- FrequencyDemod(SampleSource<std::complex<float>> *src);
+ FrequencyDemod(std::shared_ptr<SampleSource<std::complex<float>>> src);
void work(void *input, void *output, int count, off_t sampleid) override;
};
View
@@ -34,27 +34,25 @@ Plot* Plots::samplePlot(std::shared_ptr<AbstractSampleSource> source)
Plot* Plots::amplitudePlot(std::shared_ptr<AbstractSampleSource> source)
{
+ typedef SampleSource<std::complex<float>> ss;
+ std::shared_ptr<ss> cs = std::dynamic_pointer_cast<ss>(source);
return new TracePlot(
- std::make_shared<AmplitudeDemod>(
- std::dynamic_pointer_cast<SampleSource<std::complex<float>>>(source).get()
- )
+ std::make_shared<AmplitudeDemod>(cs)
);
}
Plot* Plots::frequencyPlot(std::shared_ptr<AbstractSampleSource> source)
{
+ typedef SampleSource<std::complex<float>> ss;
+ std::shared_ptr<ss> cs = std::dynamic_pointer_cast<ss>(source);
return new TracePlot(
- std::make_shared<FrequencyDemod>(
- std::dynamic_pointer_cast<SampleSource<std::complex<float>>>(source).get()
- )
+ std::make_shared<FrequencyDemod>(cs)
);
}
Plot* Plots::thresholdPlot(std::shared_ptr<AbstractSampleSource> source)
{
- return new TracePlot(
- std::make_shared<Threshold>(
- std::dynamic_pointer_cast<SampleSource<float>>(source).get()
- )
- );
-}
+ typedef SampleSource<float> ss;
+ std::shared_ptr<ss> cs = std::dynamic_pointer_cast<ss>(source);
+ return new TracePlot( std::make_shared<Threshold>( cs ) );
+}
View
@@ -22,7 +22,7 @@
#include "samplebuffer.h"
template <typename Tin, typename Tout>
-SampleBuffer<Tin, Tout>::SampleBuffer(SampleSource<Tin> *src) : src(src)
+SampleBuffer<Tin, Tout>::SampleBuffer(std::shared_ptr<SampleSource<Tin>> src) : src(src)
{
src->subscribe(this);
}
View
@@ -28,11 +28,11 @@ template <typename Tin, typename Tout>
class SampleBuffer : public SampleSource<Tout>, public Subscriber
{
private:
- SampleSource<Tin> *src;
+ std::shared_ptr<SampleSource<Tin>> src;
QMutex mutex;
public:
- SampleBuffer(SampleSource<Tin> *src);
+ SampleBuffer(std::shared_ptr<SampleSource<Tin>> src);
~SampleBuffer();
void invalidateEvent();
virtual std::unique_ptr<Tout[]> getSamples(off_t start, off_t length);
View
@@ -45,7 +45,7 @@ SpectrogramPlot::SpectrogramPlot(std::shared_ptr<SampleSource<std::complex<float
colormap[i] = QColor::fromHsvF(p * 0.83f, 1.0, 1.0 - p).rgba();
}
- tunerTransform = std::make_shared<TunerTransform>(src.get());
+ tunerTransform = std::make_shared<TunerTransform>(src);
connect(&tuner, &Tuner::tunerMoved, this, &SpectrogramPlot::tunerMoved);
src->subscribe(this);
}
View
@@ -19,7 +19,7 @@
#include "threshold.h"
-Threshold::Threshold(SampleSource<float> *src) : SampleBuffer(src)
+Threshold::Threshold(std::shared_ptr<SampleSource<float>> src) : SampleBuffer(src)
{
}
View
@@ -24,6 +24,6 @@
class Threshold : public SampleBuffer<float, float>
{
public:
- Threshold(SampleSource<float> *src);
+ Threshold(std::shared_ptr<SampleSource<float>> src);
void work(void *input, void *output, int count, off_t sampleid) override;
};
View
@@ -21,7 +21,7 @@
#include <liquid/liquid.h>
#include "util.h"
-TunerTransform::TunerTransform(SampleSource<std::complex<float>> *src) : SampleBuffer(src), frequency(0), bandwidth(1.), taps{1.0f}
+TunerTransform::TunerTransform(std::shared_ptr<SampleSource<std::complex<float>>> src) : SampleBuffer(src), frequency(0), bandwidth(1.), taps{1.0f}
{
}
View
@@ -30,7 +30,7 @@ class TunerTransform : public SampleBuffer<std::complex<float>, std::complex<flo
std::vector<float> taps;
public:
- TunerTransform(SampleSource<std::complex<float>> *src);
+ TunerTransform(std::shared_ptr<SampleSource<std::complex<float>>> src);
void work(void *input, void *output, int count, off_t sampleid) override;
void setFrequency(float frequency);
void setTaps(std::vector<float> taps);

0 comments on commit 23490a0

Please sign in to comment.