From: Steinar H. Gunderson Date: Sat, 5 Apr 2014 00:16:14 +0000 (+0200) Subject: Fix a leak in DiffusionEffect in an edge case. X-Git-Tag: 1.1~3 X-Git-Url: https://git.sesse.net/?p=movit;a=commitdiff_plain;h=1b46606b3c5d6a7a97528a53d0309d3cd04df62b Fix a leak in DiffusionEffect in an edge case. Found by Coverity Scan. --- diff --git a/diffusion_effect.cpp b/diffusion_effect.cpp index 145eaf6..afec9c8 100644 --- a/diffusion_effect.cpp +++ b/diffusion_effect.cpp @@ -12,10 +12,18 @@ namespace movit { DiffusionEffect::DiffusionEffect() : blur(new BlurEffect), - overlay_matte(new OverlayMatteEffect) + overlay_matte(new OverlayMatteEffect), + owns_overlay_matte(true) { } +DiffusionEffect::~DiffusionEffect() +{ + if (owns_overlay_matte) { + delete overlay_matte; + } +} + void DiffusionEffect::rewrite_graph(EffectChain *graph, Node *self) { assert(self->incoming_links.size() == 1); @@ -23,6 +31,7 @@ void DiffusionEffect::rewrite_graph(EffectChain *graph, Node *self) Node *blur_node = graph->add_node(blur); Node *overlay_matte_node = graph->add_node(overlay_matte); + owns_overlay_matte = false; graph->replace_receiver(self, overlay_matte_node); graph->connect_nodes(input, blur_node); graph->connect_nodes(blur_node, overlay_matte_node); diff --git a/diffusion_effect.h b/diffusion_effect.h index 82eda93..64b94dd 100644 --- a/diffusion_effect.h +++ b/diffusion_effect.h @@ -28,6 +28,7 @@ class OverlayMatteEffect; class DiffusionEffect : public Effect { public: DiffusionEffect(); + ~DiffusionEffect(); virtual std::string effect_type_id() const { return "DiffusionEffect"; } virtual void rewrite_graph(EffectChain *graph, Node *self); @@ -43,6 +44,7 @@ public: private: BlurEffect *blur; OverlayMatteEffect *overlay_matte; + bool owns_overlay_matte; }; // Used internally by DiffusionEffect; combines the blurred and the original