]> git.sesse.net Git - movit/commitdiff
Fix a leak if ResampleEffect is destroyed before being put on a chain.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 7 Aug 2017 07:32:21 +0000 (09:32 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 7 Aug 2017 07:32:59 +0000 (09:32 +0200)
FFTConvolutionEffect remembered this, but ResampleEffect did not.
Patch by Dan Dennedy.

resample_effect.cpp
resample_effect.h

index 86d574b32d6468f22688a7c894de6356f1895909..453a83832f7cb5d905a11b49951ac63a6f14cc12 100644 (file)
@@ -301,7 +301,8 @@ double compute_sum_sq_error(const Tap<float>* weights, unsigned num_weights,
 }  // namespace
 
 ResampleEffect::ResampleEffect()
-       : input_width(1280),
+       : owns_effects(true),
+         input_width(1280),
          input_height(720),
          offset_x(0.0f), offset_y(0.0f),
          zoom_x(1.0f), zoom_y(1.0f),
@@ -319,6 +320,14 @@ ResampleEffect::ResampleEffect()
        update_size();
 }
 
+ResampleEffect::~ResampleEffect()
+{
+       if (owns_effects) {
+               delete hpass;
+               delete vpass;
+       }
+}
+
 void ResampleEffect::rewrite_graph(EffectChain *graph, Node *self)
 {
        Node *hpass_node = graph->add_node(hpass);
@@ -327,6 +336,7 @@ void ResampleEffect::rewrite_graph(EffectChain *graph, Node *self)
        graph->replace_receiver(self, hpass_node);
        graph->replace_sender(self, vpass_node);
        self->disabled = true;
+       owns_effects = false;
 } 
 
 // We get this information forwarded from the first blur pass,
index 7cd613fb34950d1620bceb257ce66cacd69536a8..ceae920aa71c98a0799a8423f173bc9e13c25876 100644 (file)
@@ -48,6 +48,7 @@ ScalingWeights calculate_scaling_weights(unsigned src_size, unsigned dst_size, f
 class ResampleEffect : public Effect {
 public:
        ResampleEffect();
+       ~ResampleEffect();
 
        virtual std::string effect_type_id() const { return "ResampleEffect"; }
 
@@ -72,6 +73,9 @@ private:
        void update_size();
        void update_offset_and_zoom();
        
+       // Both of these are owned by us if owns_effects is true (before finalize()),
+       // and otherwise owned by the EffectChain.
+       bool owns_effects;
        SingleResamplePassEffect *hpass, *vpass;
        int input_width, input_height, output_width, output_height;