From: Daniel Silverstone Date: Sun, 29 Jul 2018 09:20:38 +0000 (+0100) Subject: Fix various bugs which caused ASAN and UBSAN to be upset X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=8b42b87e23dd3bd6d3a3e5c8f7693852f33087be;p=libsvgtiny.git Fix various bugs which caused ASAN and UBSAN to be upset --- diff --git a/src/svgtiny.c b/src/svgtiny.c index 69cbcf7..8831b92 100644 --- a/src/svgtiny.c +++ b/src/svgtiny.c @@ -457,6 +457,7 @@ svgtiny_code svgtiny_parse_path(dom_element *path, /* empty path is permitted it just disables the path */ palloc = dom_string_byte_length(path_d_str); if (palloc == 0) { + dom_string_unref(path_d_str); svgtiny_cleanup_state_local(&state); return svgtiny_OK; } @@ -708,7 +709,7 @@ svgtiny_code svgtiny_parse_path(dom_element *path, &x, &y, &n) == 7); } else { - fprintf(stderr, "parse failed at \"%s\"\n", s); + /* fprintf(stderr, "parse failed at \"%s\"\n", s); */ break; } } diff --git a/src/svgtiny_gradient.c b/src/svgtiny_gradient.c index b282f45..4b327dd 100644 --- a/src/svgtiny_gradient.c +++ b/src/svgtiny_gradient.c @@ -237,7 +237,7 @@ svgtiny_code svgtiny_parse_linear_gradient(dom_element *linear, (const uint8_t *) s, strcspn(s, "; "), &value); - if (exc != DOM_NO_ERR && + if (exc == DOM_NO_ERR && value != NULL) { svgtiny_parse_color(value, &color, @@ -420,8 +420,10 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n, gradient_norm_squared = gradient_dx * gradient_dx + gradient_dy * gradient_dy; pts = svgtiny_list_create(sizeof (struct grad_point)); - if (!pts) + if (!pts) { + free(p); return svgtiny_OUT_OF_MEMORY; + } for (j = 0; j != n; ) { int segment_type = (int) p[j]; struct grad_point *point; @@ -446,6 +448,7 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n, gradient_norm_squared; point = svgtiny_list_push(pts); if (!point) { + free(p); svgtiny_list_free(pts); return svgtiny_OUT_OF_MEMORY; } @@ -524,6 +527,7 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n, #endif point = svgtiny_list_push(pts); if (!point) { + free(p); svgtiny_list_free(pts); return svgtiny_OUT_OF_MEMORY; } @@ -551,6 +555,7 @@ svgtiny_code svgtiny_add_path_linear_gradient(float *p, unsigned int n, /* There must be at least a single point for the gradient */ if (svgtiny_list_size(pts) == 0) { svgtiny_list_free(pts); + free(p); return svgtiny_OK; }