From a6f9ec30808ea11583f97115fb16ccd7321d3be7 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Thu, 24 Jun 2021 18:38:23 +0900 Subject: [PATCH] svg_loader: fix memory violation issues. copy attribute must copy the url data, otherwise, url memory can be atempted freeing twice. also, fix the memory leak in multiple composition case. --- src/loaders/svg/tvgSvgLoader.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index 94ab7e61..b91750e3 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -879,7 +879,11 @@ static void _handleMaskAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, con #endif style->comp.method = CompositeMethod::AlphaMask; int len = strlen(value); - if (len >= 3 && !strncmp(value, "url", 3)) style->comp.url = _idFromUrl((const char*)(value + 3)); + if (len >= 3 && !strncmp(value, "url", 3)) { + //FIXME: Support multiple composition. + if (style->comp.url) delete(style->comp.url); + style->comp.url = _idFromUrl((const char*)(value + 3)); + } } @@ -1596,6 +1600,8 @@ static void _copyAttr(SvgNode* to, const SvgNode* from) } //Copy style attribute; memcpy(to->style, from->style, sizeof(SvgStyleProperty)); + if (from->style->fill.paint.url) to->style->fill.paint.url = new string(from->style->fill.paint.url->c_str()); + if (from->style->stroke.paint.url) to->style->stroke.paint.url = new string(from->style->stroke.paint.url->c_str()); //Copy style composite attribute (clip-path, mask, ...) if (from->style->comp.url) to->style->comp.url = new string(from->style->comp.url->c_str());