summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/pdf/pdf-page.c2
-rw-r--r--source/pdf/pdf-xref.c8
-rw-r--r--source/tools/murun.c10
3 files changed, 13 insertions, 7 deletions
diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c
index 2667e184..e3c78877 100644
--- a/source/pdf/pdf-page.c
+++ b/source/pdf/pdf-page.c
@@ -668,7 +668,7 @@ pdf_add_page(fz_context *ctx, pdf_document *doc, const fz_rect *mediabox, int ro
pdf_dict_put_drop(ctx, page_obj, PDF_NAME_MediaBox, pdf_new_rect(ctx, doc, mediabox));
pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Rotate, pdf_new_int(ctx, doc, rotate));
pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Resources, pdf_add_object(ctx, doc, resources));
- pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Contents, pdf_add_stream(ctx, doc, contents));
+ pdf_dict_put_drop(ctx, page_obj, PDF_NAME_Contents, pdf_add_stream(ctx, doc, contents, NULL));
}
fz_catch(ctx)
{
diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c
index 1af2d391..6280c2ff 100644
--- a/source/pdf/pdf-xref.c
+++ b/source/pdf/pdf-xref.c
@@ -2624,9 +2624,13 @@ pdf_add_object_drop(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
}
pdf_obj *
-pdf_add_stream(fz_context *ctx, pdf_document *doc, fz_buffer *buf)
+pdf_add_stream(fz_context *ctx, pdf_document *doc, fz_buffer *buf, pdf_obj *obj)
{
- pdf_obj *ind = pdf_add_object_drop(ctx, doc, pdf_new_dict(ctx, doc, 4));
+ pdf_obj *ind;
+ if (!obj)
+ ind = pdf_add_object_drop(ctx, doc, pdf_new_dict(ctx, doc, 4));
+ else
+ ind = pdf_add_object(ctx, doc, obj);
fz_try(ctx)
pdf_update_stream(ctx, doc, ind, buf, 0);
fz_catch(ctx)
diff --git a/source/tools/murun.c b/source/tools/murun.c
index 079a8c3c..b1f95d57 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -3055,14 +3055,16 @@ static void ffi_PDFDocument_addStream(js_State *J)
{
fz_context *ctx = js_getcontext(J);
pdf_document *pdf = js_touserdata(J, 0, "pdf_document");
- fz_buffer *buf = ffi_tobuffer(J, 1);
+ fz_buffer *buf = ffi_tobuffer(J, 1); /* FIXME: leak if ffi_toobj throws */
+ pdf_obj *obj = js_iscoercible(J, 2) ? ffi_toobj(J, pdf, 2) : NULL;
pdf_obj *ind;
fz_try(ctx)
- ind = pdf_add_stream(ctx, pdf, buf);
- fz_always(ctx)
+ ind = pdf_add_stream(ctx, pdf, buf, obj);
+ fz_always(ctx) {
fz_drop_buffer(ctx, buf);
- fz_catch(ctx)
+ pdf_drop_obj(ctx, obj);
+ } fz_catch(ctx)
rethrow(J);
ffi_pushobj(J, ind);