From 229efd7807dd1831bd5b34ff83c1fb556a6e1cf1 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Fri, 28 Jul 2023 22:47:47 +0900 Subject: [PATCH] loader lottie: fixed the memory leaks. All memory leaks detected by the sanitizer have been fixed. --- src/loaders/lottie/tvgLottieBuilder.cpp | 9 ++++++--- src/loaders/lottie/tvgLottieProperty.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index be3a0975..eaef90bb 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -232,6 +232,9 @@ static void _updateChildren(LottieGroup* parent, int32_t frameNo, Shape* baseSha { if (parent->children.empty()) return; + //inherits the parent's shape properties. + baseShape = baseShape ? static_cast(baseShape->duplicate()) : Shape::gen().release(); + //merge shapes if they are continuously appended? Shape* mergingShape = nullptr; @@ -239,7 +242,7 @@ static void _updateChildren(LottieGroup* parent, int32_t frameNo, Shape* baseSha for (auto child = parent->children.end() - 1; child >= parent->children.data; --child) { switch ((*child)->type) { case LottieObject::Group: { - mergingShape = _updateGroup(parent, static_cast(*child), frameNo, static_cast(baseShape->duplicate()), reset); + mergingShape = _updateGroup(parent, static_cast(*child), frameNo, baseShape, reset); break; } case LottieObject::Transform: { @@ -288,6 +291,7 @@ static void _updateChildren(LottieGroup* parent, int32_t frameNo, Shape* baseSha } } } + delete(baseShape); } static void _updatePrecomp(LottieLayer* precomp, int32_t frameNo, bool reset) @@ -340,8 +344,7 @@ static void _updateLayer(LottieLayer* root, LottieLayer* layer, int32_t frameNo, break; } default: { - auto baseShape = Shape::gen(); - _updateChildren(layer, frameNo, baseShape.get(), reset); + _updateChildren(layer, frameNo, nullptr, reset); break; } } diff --git a/src/loaders/lottie/tvgLottieProperty.h b/src/loaders/lottie/tvgLottieProperty.h index 9ad299be..947d2495 100644 --- a/src/loaders/lottie/tvgLottieProperty.h +++ b/src/loaders/lottie/tvgLottieProperty.h @@ -46,7 +46,7 @@ struct RGB24 struct ColorStop { - Fill::ColorStop* data; + Fill::ColorStop* data = nullptr; };