Skip to content

Commit

Permalink
fixed mem leak in sgv parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlf committed Nov 7, 2022
1 parent c34fe92 commit 2191e66
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/scene_manager/loader_svg.c
Expand Up @@ -449,6 +449,7 @@ static Bool svg_parse_animation(GF_SVG_Parser *parser, GF_SceneGraph *sg, SVG_De
if (anim->to) {
/* now that we have a target, if there is a to value to parse, create the attribute and parse it */
gf_node_get_attribute_by_tag((GF_Node *)anim->animation_elt, TAG_SVG_ATT_to, GF_TRUE, GF_FALSE, &info);
if (!info.name) info.name = "to";
gf_svg_parse_attribute((GF_Node *)anim->animation_elt, &info, anim->to, anim_value_type);
if (anim_value_type==XMLRI_datatype) {
svg_post_process_href(parser, (GF_Node *) anim->target, (XMLRI*)((SMIL_AnimateValue *)info.far_ptr)->value);
Expand All @@ -457,20 +458,23 @@ static Bool svg_parse_animation(GF_SVG_Parser *parser, GF_SceneGraph *sg, SVG_De
if (anim->from) {
/* now that we have a target, if there is a from value to parse, create the attribute and parse it */
gf_node_get_attribute_by_tag((GF_Node *)anim->animation_elt, TAG_SVG_ATT_from, GF_TRUE, GF_FALSE, &info);
if (!info.name) info.name = "from";
gf_svg_parse_attribute((GF_Node *)anim->animation_elt, &info, anim->from, anim_value_type);
if (anim_value_type==XMLRI_datatype)
svg_post_process_href(parser, (GF_Node *) anim->target, (XMLRI*)((SMIL_AnimateValue *)info.far_ptr)->value);
}
if (anim->by) {
/* now that we have a target, if there is a by value to parse, create the attribute and parse it */
gf_node_get_attribute_by_tag((GF_Node *)anim->animation_elt, TAG_SVG_ATT_by, GF_TRUE, GF_FALSE, &info);
if (!info.name) info.name = "by";
gf_svg_parse_attribute((GF_Node *)anim->animation_elt, &info, anim->by, anim_value_type);
if (anim_value_type==XMLRI_datatype)
svg_post_process_href(parser, (GF_Node *) anim->target, (XMLRI*)((SMIL_AnimateValue *)info.far_ptr)->value);
}
if (anim->values) {
/* now that we have a target, if there is a 'values' value to parse, create the attribute and parse it */
gf_node_get_attribute_by_tag((GF_Node *)anim->animation_elt, TAG_SVG_ATT_values, GF_TRUE, GF_FALSE, &info);
if (!info.name) info.name = "values";
gf_svg_parse_attribute((GF_Node *)anim->animation_elt, &info, anim->values, anim_value_type);
if (anim_value_type==XMLRI_datatype) {
u32 i, count;
Expand Down Expand Up @@ -2119,13 +2123,13 @@ GF_Err load_svg_run(GF_SceneLoader *load)

in_time = gf_sys_clock();
e = gf_xml_sax_parse_file(parser->sax_parser, (const char *)load->fileName, svg_progress);
svg_flush_animations(parser);
gf_sm_svg_flush_state(parser);
if (parser->last_error<0) e = parser->last_error;

if (e<0) return svg_report(parser, e, "Unable to parse file %s: %s", load->fileName, gf_xml_sax_get_error(parser->sax_parser) );
GF_LOG(GF_LOG_INFO, GF_LOG_PARSER, ("[Parser] Scene parsed and Scene Graph built in %d ms\n", gf_sys_clock() - in_time));

svg_flush_animations(parser);
gf_sm_svg_flush_state(parser);
return e;

}
Expand Down
11 changes: 7 additions & 4 deletions src/scenegraph/svg_attributes.c
Expand Up @@ -2994,7 +2994,7 @@ static void svg_parse_preserveaspectratio(SVG_PreserveAspectRatio *par, char *at
while (*content == ' ') content++;
if (strstr(content, "defer")) {
par->defer = 1;
content += 4;
content += 5;
} else {
content = attribute_content;
}
Expand Down Expand Up @@ -3587,11 +3587,14 @@ GF_Err gf_svg_parse_attribute(GF_Node *n, GF_FieldInfo *info, char *attribute_co
*(SVG_String *)info->far_ptr = gf_strdup(attribute_content);
break;
default:
GF_LOG(GF_LOG_WARNING, GF_LOG_PARSER, ("[SVG Parsing] Cannot parse attribute %s\n", info->name ? info->name : ""));
break;
GF_LOG(GF_LOG_WARNING, GF_LOG_PARSER, ("[SVG Parsing] Cannot parse attribute \"%s\"\n", info->name ? info->name : ""));
return GF_OK;
}
if (e) {
GF_LOG(GF_LOG_ERROR, GF_LOG_PARSER, ("[SVG Parsing] Cannot parse attribute %s value %s: %s\n", info->name ? info->name : "", attribute_content, gf_error_to_string(e)));
GF_LOG(GF_LOG_ERROR, GF_LOG_PARSER, ("[SVG Parsing] Cannot parse attribute \"%s\" value %s: %s\n", info->name ? info->name : "", attribute_content, gf_error_to_string(e)));
//continue parsing if not test mode
if (!gf_sys_is_test_mode())
e = GF_OK;
}
return e;
}
Expand Down

0 comments on commit 2191e66

Please sign in to comment.