summaryrefslogtreecommitdiff
path: root/fitz
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2013-06-04 19:15:31 +0100
committerRobin Watts <robin.watts@artifex.com>2013-06-05 16:01:13 +0100
commit40599eb00e746c0aa6e86a46115a109e073a8890 (patch)
tree1c4b5af90e169de50a39da0df24bcc4354d63482 /fitz
parente92dd2a341223487e87a9088164725f0a40ad27c (diff)
downloadmupdf-40599eb00e746c0aa6e86a46115a109e073a8890.tar.xz
Fix XPS leaking fz_buffers for images.
fz_new_image_from_buffer was building a new buffer from the data in the supplied buffer, rather than just using the supplied buffer. Also move the code into line with our standards; don't pass ownership of the buffer.
Diffstat (limited to 'fitz')
-rw-r--r--fitz/res_image.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/fitz/res_image.c b/fitz/res_image.c
index 0454f6bd..4aac14ae 100644
--- a/fitz/res_image.c
+++ b/fitz/res_image.c
@@ -417,9 +417,29 @@ fz_new_image(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colorspace,
fz_image *
fz_new_image_from_data(fz_context *ctx, unsigned char *data, int len)
{
- fz_buffer *buffer = fz_new_buffer_from_data(ctx, data, len);
+ fz_buffer *buffer = NULL;
+ fz_image *image;
+
+ fz_var(buffer);
+ fz_var(data);
+
+ fz_try(ctx)
+ {
+ buffer = fz_new_buffer_from_data(ctx, data, len);
+ data = NULL;
+ image = fz_new_image_from_buffer(ctx, buffer);
+ }
+ fz_always(ctx)
+ {
+ fz_drop_buffer(ctx, buffer);
+ }
+ fz_catch(ctx)
+ {
+ fz_free(ctx, data);
+ fz_rethrow(ctx);
+ }
- return fz_new_image_from_buffer(ctx, buffer);
+ return image;
}
fz_image *
@@ -428,12 +448,10 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer)
fz_compressed_buffer *bc = NULL;
int w, h, xres, yres;
fz_colorspace *cspace;
- fz_buffer *drop_buffer = buffer;
int len = buffer->len;
unsigned char *buf = buffer->data;
fz_var(bc);
- fz_var(drop_buffer);
fz_try(ctx)
{
@@ -441,8 +459,7 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer)
fz_throw(ctx, "unknown image file format");
bc = fz_malloc_struct(ctx, fz_compressed_buffer);
- bc->buffer = fz_new_buffer_from_data(ctx, buf, len);
- drop_buffer = NULL;
+ bc->buffer = fz_keep_buffer(ctx, buffer);
if (buf[0] == 0xff && buf[1] == 0xd8)
{
@@ -467,7 +484,6 @@ fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer)
}
fz_catch(ctx)
{
- fz_drop_buffer(ctx, drop_buffer);
fz_free_compressed_buffer(ctx, bc);
fz_rethrow(ctx);
}