diff options
Diffstat (limited to 'draw')
-rw-r--r-- | draw/draw_device.c | 2 | ||||
-rw-r--r-- | draw/draw_edge.c | 47 | ||||
-rw-r--r-- | draw/draw_glyph.c | 2 |
3 files changed, 34 insertions, 17 deletions
diff --git a/draw/draw_device.c b/draw/draw_device.c index cc8f5474..0a1cc812 100644 --- a/draw/draw_device.c +++ b/draw/draw_device.c @@ -1532,7 +1532,7 @@ fz_device * fz_new_draw_device(fz_context *ctx, fz_glyph_cache *cache, fz_pixmap *dest) { fz_device *dev; - fz_draw_device *ddev = fz_malloc(ctx, sizeof(fz_draw_device)); + fz_draw_device *ddev = fz_malloc_struct(ctx, fz_draw_device); ddev->cache = cache; ddev->gel = fz_new_gel(ctx); ddev->dest = dest; diff --git a/draw/draw_edge.c b/draw/draw_edge.c index ec1c1ea8..952050fa 100644 --- a/draw/draw_edge.c +++ b/draw/draw_edge.c @@ -26,7 +26,7 @@ struct fz_aa_context_s void fz_new_aa_context(fz_context *ctx) { #ifndef AA_BITS - ctx->aa = fz_malloc(ctx, sizeof(*ctx->aa)); + ctx->aa = fz_malloc_struct(ctx, fz_aa_context); ctx->aa->hscale = 17; ctx->aa->vscale = 15; ctx->aa->scale = 256; @@ -166,21 +166,32 @@ fz_new_gel(fz_context *ctx) { fz_gel *gel; - gel = fz_malloc(ctx, sizeof(fz_gel)); - gel->ctx = ctx; - gel->cap = 512; - gel->len = 0; - gel->edges = fz_malloc_array(ctx, gel->cap, sizeof(fz_edge)); + gel = fz_malloc_struct(ctx, fz_gel); + fz_try(ctx) + { + gel->edges = NULL; + gel->ctx = ctx; + gel->cap = 512; + gel->len = 0; + gel->edges = fz_malloc_array(ctx, gel->cap, sizeof(fz_edge)); - gel->clip.x0 = gel->clip.y0 = BBOX_MAX; - gel->clip.x1 = gel->clip.y1 = BBOX_MIN; + gel->clip.x0 = gel->clip.y0 = BBOX_MAX; + gel->clip.x1 = gel->clip.y1 = BBOX_MIN; - gel->bbox.x0 = gel->bbox.y0 = BBOX_MAX; - gel->bbox.x1 = gel->bbox.y1 = BBOX_MIN; + gel->bbox.x0 = gel->bbox.y0 = BBOX_MAX; + gel->bbox.x1 = gel->bbox.y1 = BBOX_MIN; - gel->acap = 64; - gel->alen = 0; - gel->active = fz_malloc_array(ctx, gel->acap, sizeof(fz_edge*)); + gel->acap = 64; + gel->alen = 0; + gel->active = fz_malloc_array(ctx, gel->acap, sizeof(fz_edge*)); + } + fz_catch(ctx) + { + if (gel) + fz_free(ctx, gel->edges); + fz_free(ctx, gel); + fz_rethrow(ctx); + } return gel; } @@ -636,8 +647,14 @@ fz_scan_convert_aa(fz_gel *gel, int eofill, fz_bbox clip, assert(clip.x0 >= xmin); assert(clip.x1 <= xmax); - alphas = fz_malloc(ctx, xmax - xmin + 1); - deltas = fz_malloc(ctx, (xmax - xmin + 1) * sizeof(int)); + alphas = fz_malloc_no_throw(ctx, xmax - xmin + 1); + deltas = fz_malloc_no_throw(ctx, (xmax - xmin + 1) * sizeof(int)); + if (alphas == NULL || deltas == NULL) + { + fz_free(ctx, alphas); + fz_free(ctx, deltas); + fz_throw(ctx, "scan conversion failed (malloc failure)"); + } memset(deltas, 0, (xmax - xmin + 1) * sizeof(int)); e = 0; diff --git a/draw/draw_glyph.c b/draw/draw_glyph.c index 30f18a5f..328b79f7 100644 --- a/draw/draw_glyph.c +++ b/draw/draw_glyph.c @@ -26,7 +26,7 @@ fz_new_glyph_cache(fz_context *ctx) { fz_glyph_cache *cache; - cache = fz_malloc(ctx, sizeof(fz_glyph_cache)); + cache = fz_malloc_struct(ctx, fz_glyph_cache); fz_try(ctx) { cache->hash = fz_new_hash_table(ctx, 509, sizeof(fz_glyph_key)); |