summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-stream.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2014-01-09 17:12:44 +0000
committerRobin Watts <robin.watts@artifex.com>2014-01-10 12:57:20 +0000
commita83c2bc591d584b2b6a8f98d7032e3d53f09ed93 (patch)
treed9e9d7ca66f779a84505fca659e978005e8e7556 /source/pdf/pdf-stream.c
parentcd84c92e68a7a3131895c469294235159ffab4dd (diff)
downloadmupdf-a83c2bc591d584b2b6a8f98d7032e3d53f09ed93.tar.xz
Fix build_filter_chain not to leak if pdf_array_get fails.
In the existing code, if build_filter fails, chain will be freed. If pdf_array_get fails however, it will leak. Rectify this. No specific bug or example file, just observation arising from discussions about previous commit.
Diffstat (limited to 'source/pdf/pdf-stream.c')
-rw-r--r--source/pdf/pdf-stream.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c
index e2b8c47e..e0b809c7 100644
--- a/source/pdf/pdf-stream.c
+++ b/source/pdf/pdf-stream.c
@@ -236,13 +236,26 @@ build_filter_chain(fz_stream *chain, pdf_document *doc, pdf_obj *fs, pdf_obj *ps
pdf_obj *f;
pdf_obj *p;
int i, n;
+ fz_context *ctx = chain->ctx;
- n = pdf_array_len(fs);
- for (i = 0; i < n; i++)
+ fz_try(ctx)
+ {
+ n = pdf_array_len(fs);
+ for (i = 0; i < n; i++)
+ {
+ fz_stream *chain2;
+
+ f = pdf_array_get(fs, i);
+ p = pdf_array_get(ps, i);
+ chain2 = chain;
+ chain = NULL;
+ chain = build_filter(chain2, doc, f, p, num, gen, (i == n-1 ? params : NULL));
+ }
+ }
+ fz_catch(ctx)
{
- f = pdf_array_get(fs, i);
- p = pdf_array_get(ps, i);
- chain = build_filter(chain, doc, f, p, num, gen, (i == n-1 ? params : NULL));
+ fz_close(chain);
+ fz_rethrow(ctx);
}
return chain;