]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
src/svgtiny.c: clean up "styles" in svgtiny_parse_svg()
authorMichael Orlitzky <michael@orlitzky.com>
Sat, 19 Oct 2024 23:24:15 +0000 (19:24 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Sun, 20 Oct 2024 21:48:28 +0000 (17:48 -0400)
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.

src/svgtiny.c

index 193164beeb9833a0f549d89c7755879b6ca7a0de..bc77cd04576c2c607527a49bff838cda1dd84a9c 100644 (file)
@@ -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;
                }