dom_node_unref(svg);
dom_node_unref(document);
- /* Only override the true exit code with a failure from this
- * "destroy" if a more meaningful error code is not already
- * set. */
+ /* Clean up the select_ctx and any sheets that were appended
+ * to it along the way. These sheets are allocated in
+ * svgtiny_parse_style_element(), and the only references we
+ * have to them are the ones in state.select_ctx->sheets.
+ * Those are const, but we are indeed responsible for the
+ * resources, so the un-const cast below is kosher.
+ *
+ * Some of these destructors can technically fail, but we only
+ * override the exit code with a failure from a destructor if
+ * a more meaningful error code is not already set. */
+ unsigned int i;
+ uint32_t n_sheets;
+ const css_stylesheet* sheet;
+ css_select_ctx_count_sheets(state.select_ctx, &n_sheets);
+ for (i = 0; i < n_sheets; i++) {
+ css_code = css_select_ctx_get_sheet(state.select_ctx, i, &sheet);
+ if (css_code != CSS_OK && code == svgtiny_OK) {
+ code = svgtiny_LIBCSS_ERROR;
+ }
+ css_code = css_stylesheet_destroy((css_stylesheet*)sheet);
+ if (css_code != CSS_OK && code == svgtiny_OK) {
+ code = svgtiny_LIBCSS_ERROR;
+ }
+ }
css_code = css_select_ctx_destroy(state.select_ctx);
if (css_code != CSS_OK && code == svgtiny_OK) {
code = svgtiny_LIBCSS_ERROR;
}
dom_string_unref(data);
+
+ /* The only reference we retain to the newly-allocated "sheet"
+ * is via state.select_ctx->sheets. Eventually, we will
+ * destroy the sheet immediately prior to destroying the
+ * context. */
return svgtiny_OK;
}