mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 06:34:01 +00:00
svg_loader: memory leak after improper stop tag
<stop> tag should be always a child of a <linearGradient> or <radialGradient> element, but there were files with <stop> tag inside <rect>. This patch fixes a memory leak if no gradient is defined before <stop> tag.
This commit is contained in:
parent
935b8592f1
commit
b005f97bcd
1 changed files with 7 additions and 3 deletions
|
@ -2232,15 +2232,19 @@ static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content,
|
|||
}
|
||||
loader->latestGradient = gradient;
|
||||
} else if (!strcmp(tagName, "stop")) {
|
||||
if (!loader->latestGradient) {
|
||||
#ifdef THORVG_LOG_ENABLED
|
||||
printf("SVG: Gradient stop but no gradient in the scope\n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
auto stop = static_cast<Fill::ColorStop*>(calloc(1, sizeof(Fill::ColorStop)));
|
||||
if (!stop) return;
|
||||
loader->svgParse->gradStop = stop;
|
||||
/* default value for opacity */
|
||||
stop->a = 255;
|
||||
simpleXmlParseAttributes(attrs, attrsLength, _attrParseStops, loader);
|
||||
if (loader->latestGradient) {
|
||||
loader->latestGradient->stops.push(stop);
|
||||
}
|
||||
loader->latestGradient->stops.push(stop);
|
||||
}
|
||||
#ifdef THORVG_LOG_ENABLED
|
||||
else {
|
||||
|
|
Loading…
Add table
Reference in a new issue