From 515c0106845a7dafd71abba6b29305e39c88380e Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 4 Sep 2013 17:32:42 +0100 Subject: Fix memory leak due to softmasks. A user (sebblonline) reports a problem when rendering the 300Meg document downloadable from: http://www.mitsubishicarbide.com/EU/de/product/epaper/index.html (7th icon on the bottom). Memento builds report that softmask objects are leaked. Tracing these it appears that the handling of softmasks in pdf_run_xobject is not quite nested right. Fixing this reveals another problem with clipping paths being doubly removed. Adding a gsave/grestore pair solves this and leaves us with a well behaved program. --- source/pdf/pdf-interpret.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'source/pdf') diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c index 0ed30026..9de4c833 100644 --- a/source/pdf/pdf-interpret.c +++ b/source/pdf/pdf-interpret.c @@ -1548,8 +1548,9 @@ pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, const fz_ma gstate->fill.alpha = 1; } - /* clip to the bounds */ + pdf_gsave(csi); /* Save here so the clippath doesn't persist */ + /* clip to the bounds */ fz_moveto(ctx, csi->path, xobj->bbox.x0, xobj->bbox.y0); fz_lineto(ctx, csi->path, xobj->bbox.x1, xobj->bbox.y0); fz_lineto(ctx, csi->path, xobj->bbox.x1, xobj->bbox.y1); @@ -1567,6 +1568,15 @@ pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, const fz_ma } fz_always(ctx) { + pdf_grestore(csi); /* Remove the clippath */ + + /* wrap up transparency stacks */ + if (xobj->transparency) + { + fz_end_group(csi->dev); + end_softmask(csi, &softmask); + } + csi->gstate[csi->gparent].ctm = gparent_save_ctm; csi->gparent = gparent_save; @@ -1579,13 +1589,6 @@ pdf_run_xobject(pdf_csi *csi, pdf_obj *resources, pdf_xobject *xobj, const fz_ma } pdf_unmark_obj(xobj->me); - - /* wrap up transparency stacks */ - if (xobj->transparency) - { - fz_end_group(csi->dev); - end_softmask(csi, &softmask); - } } fz_catch(ctx) { -- cgit v1.2.3