From 09a016ee7c5c81580b27db3bd193b38cb3bd4f0e Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Fri, 16 Dec 2011 16:26:48 +0000 Subject: Add fz_malloc_struct, and make code use it. The new fz_malloc_struct(A,B) macro allocates sizeof(B) bytes using fz_malloc, and then passes the resultant pointer to Memento_label to label it with "B". This costs nothing in non-memento builds, but gives much nicer listings of leaked blocks when memento is enabled. --- draw/draw_edge.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'draw/draw_edge.c') 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; -- cgit v1.2.3