[cairo] Handle malloc failure
diff --git a/src/hb-cairo-utils.cc b/src/hb-cairo-utils.cc
index 7b4ccef..77b3cb0 100644
--- a/src/hb-cairo-utils.cc
+++ b/src/hb-cairo-utils.cc
@@ -274,7 +274,7 @@
*omax = max;
}
-static void
+static bool
_hb_cairo_get_color_stops (hb_cairo_context_t *c,
hb_color_line_t *color_line,
unsigned *count,
@@ -282,7 +282,11 @@
{
unsigned len = hb_color_line_get_color_stops (color_line, 0, nullptr, nullptr);
if (len > *count)
+ {
*stops = (hb_color_stop_t *) hb_malloc (len * sizeof (hb_color_stop_t));
+ if (unlikely (!stops))
+ return false;
+ }
hb_color_line_get_color_stops (color_line, 0, &len, *stops);
for (unsigned i = 0; i < len; i++)
if ((*stops)[i].is_foreground)
@@ -299,6 +303,7 @@
}
*count = len;
+ return true;
}
void
@@ -318,7 +323,8 @@
float min, max;
cairo_pattern_t *pattern;
- _hb_cairo_get_color_stops (c, color_line, &len, &stops);
+ if (unlikely (!_hb_cairo_get_color_stops (c, color_line, &len, &stops)))
+ return;
_hb_cairo_normalize_color_line (stops, len, &min, &max);
_hb_cairo_reduce_anchors (x0, y0, x1, y1, x2, y2, &xx0, &yy0, &xx1, &yy1);
@@ -365,7 +371,8 @@
float rr0, rr1;
cairo_pattern_t *pattern;
- _hb_cairo_get_color_stops (c, color_line, &len, &stops);
+ if (unlikely (!_hb_cairo_get_color_stops (c, color_line, &len, &stops)))
+ return;
_hb_cairo_normalize_color_line (stops, len, &min, &max);
xx0 = x0 + min * (x1 - x0);
@@ -626,6 +633,12 @@
{
angles = (float *) hb_malloc (sizeof (float) * n_stops);
colors = (hb_cairo_color_t *) hb_malloc (sizeof (hb_cairo_color_t) * n_stops);
+ if (unlikely (!angles || !colors))
+ {
+ hb_free (angles);
+ hb_free (colors);
+ return;
+ }
}
for (unsigned i = 0; i < n_stops; i++)
@@ -828,7 +841,8 @@
float max_x, max_y, radius;
cairo_pattern_t *pattern;
- _hb_cairo_get_color_stops (c, color_line, &len, &stops);
+ if (unlikely (!_hb_cairo_get_color_stops (c, color_line, &len, &stops)))
+ return;
hb_qsort (stops, len, sizeof (hb_color_stop_t), _hb_cairo_cmp_color_stop);