mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 12:34:30 +00:00
svg_loader: prevent mem leaks
A necessary check added before strdup function is called
This commit is contained in:
parent
b24e7c7402
commit
be4f382d99
2 changed files with 25 additions and 6 deletions
|
@ -128,8 +128,14 @@ void cssCopyStyleAttr(SvgNode* to, const SvgNode* from)
|
||||||
//Copy style attribute
|
//Copy style attribute
|
||||||
_copyStyle(to->style, from->style);
|
_copyStyle(to->style, from->style);
|
||||||
|
|
||||||
if (from->style->clipPath.url) to->style->clipPath.url = strdup(from->style->clipPath.url);
|
if (from->style->clipPath.url) {
|
||||||
if (from->style->mask.url) to->style->mask.url = strdup(from->style->mask.url);
|
if (to->style->clipPath.url) free(to->style->clipPath.url);
|
||||||
|
to->style->clipPath.url = strdup(from->style->clipPath.url);
|
||||||
|
}
|
||||||
|
if (from->style->mask.url) {
|
||||||
|
if (to->style->mask.url) free(to->style->mask.url);
|
||||||
|
to->style->mask.url = strdup(from->style->mask.url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1332,6 +1332,7 @@ static bool _attrParsePathNode(void* data, const char* key, const char* value)
|
||||||
SvgPathNode* path = &(node->node.path);
|
SvgPathNode* path = &(node->node.path);
|
||||||
|
|
||||||
if (!strcmp(key, "d")) {
|
if (!strcmp(key, "d")) {
|
||||||
|
if (path->path) free(path->path);
|
||||||
//Temporary: need to copy
|
//Temporary: need to copy
|
||||||
path->path = _copyId(value);
|
path->path = _copyId(value);
|
||||||
} else if (!strcmp(key, "style")) {
|
} else if (!strcmp(key, "style")) {
|
||||||
|
@ -2005,8 +2006,14 @@ static void _copyAttr(SvgNode* to, const SvgNode* from)
|
||||||
//Copy style attribute
|
//Copy style attribute
|
||||||
_styleCopy(to->style, from->style);
|
_styleCopy(to->style, from->style);
|
||||||
to->style->flags = (SvgStyleFlags)((int)to->style->flags | (int)from->style->flags);
|
to->style->flags = (SvgStyleFlags)((int)to->style->flags | (int)from->style->flags);
|
||||||
if (from->style->clipPath.url) to->style->clipPath.url = strdup(from->style->clipPath.url);
|
if (from->style->clipPath.url) {
|
||||||
if (from->style->mask.url) to->style->mask.url = strdup(from->style->mask.url);
|
if (to->style->clipPath.url) free(to->style->clipPath.url);
|
||||||
|
to->style->clipPath.url = strdup(from->style->clipPath.url);
|
||||||
|
}
|
||||||
|
if (from->style->mask.url) {
|
||||||
|
if (to->style->mask.url) free(to->style->mask.url);
|
||||||
|
to->style->mask.url = strdup(from->style->mask.url);
|
||||||
|
}
|
||||||
|
|
||||||
//Copy node attribute
|
//Copy node attribute
|
||||||
switch (from->type) {
|
switch (from->type) {
|
||||||
|
@ -2042,7 +2049,10 @@ static void _copyAttr(SvgNode* to, const SvgNode* from)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Path: {
|
case SvgNodeType::Path: {
|
||||||
if (from->node.path.path) to->node.path.path = strdup(from->node.path.path);
|
if (from->node.path.path) {
|
||||||
|
if (to->node.path.path) free(to->node.path.path);
|
||||||
|
to->node.path.path = strdup(from->node.path.path);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Polygon: {
|
case SvgNodeType::Polygon: {
|
||||||
|
@ -2064,7 +2074,10 @@ static void _copyAttr(SvgNode* to, const SvgNode* from)
|
||||||
to->node.image.y = from->node.image.y;
|
to->node.image.y = from->node.image.y;
|
||||||
to->node.image.w = from->node.image.w;
|
to->node.image.w = from->node.image.w;
|
||||||
to->node.image.h = from->node.image.h;
|
to->node.image.h = from->node.image.h;
|
||||||
if (from->node.image.href) to->node.image.href = strdup(from->node.image.href);
|
if (from->node.image.href) {
|
||||||
|
if (to->node.image.href) free(to->node.image.href);
|
||||||
|
to->node.image.href = strdup(from->node.image.href);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
Loading…
Add table
Reference in a new issue