From 11f2afecc201d7c4c845f5782059860ce3209a28 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 7 Aug 2017 09:32:21 +0200 Subject: [PATCH] Fix a leak if ResampleEffect is destroyed before being put on a chain. FFTConvolutionEffect remembered this, but ResampleEffect did not. Patch by Dan Dennedy. --- resample_effect.cpp | 12 +++++++++++- resample_effect.h | 4 ++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/resample_effect.cpp b/resample_effect.cpp index 86d574b..453a838 100644 --- a/resample_effect.cpp +++ b/resample_effect.cpp @@ -301,7 +301,8 @@ double compute_sum_sq_error(const Tap* 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, diff --git a/resample_effect.h b/resample_effect.h index 7cd613f..ceae920 100644 --- a/resample_effect.h +++ b/resample_effect.h @@ -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; -- 2.39.2