From 0fda4705b3194d2158f4dd3998981884cb3e8570 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 5 Aug 2012 15:37:56 +0200 Subject: Upon parse error when repairing, make sure object stream is freed Previously, during repair of a pdf, an object stream was loaded and an attempt was made at repairing the objects stored inside the object stream. Failure to repair the stream caused an exception which was not handled by the code loading the object stream, it was just passed on. This meant that the loaded object stream caused a memory leak. Now we catch that exception, free the object stream and rethrow the exception. --- pdf/pdf_repair.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pdf/pdf_repair.c b/pdf/pdf_repair.c index e892bc52..8250ebf4 100644 --- a/pdf/pdf_repair.c +++ b/pdf/pdf_repair.c @@ -506,6 +506,7 @@ pdf_repair_xref(pdf_document *xref, pdf_lexbuf *buf) void pdf_repair_obj_stms(pdf_document *xref) { + fz_context *ctx = xref->ctx; pdf_obj *dict; int i; @@ -514,9 +515,19 @@ pdf_repair_obj_stms(pdf_document *xref) if (xref->table[i].stm_ofs) { dict = pdf_load_object(xref, i, 0); - if (!strcmp(pdf_to_name(pdf_dict_gets(dict, "Type")), "ObjStm")) - pdf_repair_obj_stm(xref, i, 0); - pdf_drop_obj(dict); + fz_try(ctx) + { + if (!strcmp(pdf_to_name(pdf_dict_gets(dict, "Type")), "ObjStm")) + pdf_repair_obj_stm(xref, i, 0); + } + fz_always(ctx) + { + pdf_drop_obj(dict); + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } } } -- cgit v1.2.3