]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
Fix various bugs which caused ASAN and UBSAN to be upset
authorDaniel Silverstone <dsilvers@digital-scurf.org>
Sun, 29 Jul 2018 09:20:38 +0000 (10:20 +0100)
committerDaniel Silverstone <dsilvers@digital-scurf.org>
Sun, 29 Jul 2018 09:20:38 +0000 (10:20 +0100)
src/svgtiny.c
src/svgtiny_gradient.c

index 69cbcf7125b2f7ae540d5743e40be7d0edf3200f..8831b92111a67699b88fc5c91c56c31559fdb073 100644 (file)
@@ -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;
                }
        }
index b282f45cb35d61738fd63cc9e4ace784c986d03a..4b327ddbcc2045260bb35f2f590e0fcd99478be7 100644 (file)
@@ -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;
         }