From: Michael Orlitzky Date: Sat, 19 Oct 2024 23:24:15 +0000 (-0400) Subject: src/svgtiny.c: clean up "styles" in svgtiny_parse_svg() X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=655a5d904279bf6eefa9dd071e4bdba4c395857e;p=libsvgtiny.git src/svgtiny.c: clean up "styles" in svgtiny_parse_svg() We allocate "styles" at the beginning of svgtiny_parse_svg(), but only clean it up at the very end, and not along any of the error paths. This commit adds a bunch of css_select_results_destroy() calls along those paths to ensure that we don't leak resources. --- diff --git a/src/svgtiny.c b/src/svgtiny.c index 193164b..bc77cd0 100644 --- a/src/svgtiny.c +++ b/src/svgtiny.c @@ -998,6 +998,7 @@ svgtiny_code svgtiny_parse_svg(dom_element *svg, exc = dom_element_get_attribute(svg, state.interned_viewBox, &view_box); if (exc != DOM_NO_ERR) { + css_select_results_destroy(styles); svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } @@ -1023,6 +1024,7 @@ svgtiny_code svgtiny_parse_svg(dom_element *svg, exc = dom_node_get_first_child(svg, (dom_node **) (void *) &child); if (exc != DOM_NO_ERR) { + css_select_results_destroy(styles); svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } @@ -1042,6 +1044,7 @@ svgtiny_code svgtiny_parse_svg(dom_element *svg, exc = dom_node_get_node_type(child, &nodetype); if (exc != DOM_NO_ERR) { dom_node_unref(child); + css_select_results_destroy(styles); svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } @@ -1050,6 +1053,7 @@ svgtiny_code svgtiny_parse_svg(dom_element *svg, exc = dom_node_get_node_name(child, &nodename); if (exc != DOM_NO_ERR) { dom_node_unref(child); + css_select_results_destroy(styles); svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; } @@ -1090,6 +1094,7 @@ svgtiny_code svgtiny_parse_svg(dom_element *svg, } if (code != svgtiny_OK) { dom_node_unref(child); + css_select_results_destroy(styles); svgtiny_cleanup_state_local(&state); return code; } @@ -1097,6 +1102,7 @@ svgtiny_code svgtiny_parse_svg(dom_element *svg, (dom_node **) (void *) &next); dom_node_unref(child); if (exc != DOM_NO_ERR) { + css_select_results_destroy(styles); svgtiny_cleanup_state_local(&state); return svgtiny_LIBDOM_ERROR; }