Skip to content

Commit ec2b7d3

Browse files
committed
Ensure mask buffer is properly freed
1 parent a8d9d5b commit ec2b7d3

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/extra.i

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3504,10 +3504,11 @@ void JM_make_image_block(fz_stext_block *block, PyObject *block_dict)
35043504
{
35053505
fz_context* ctx = mupdf::internal_context_get();
35063506
fz_image *image = block->u.i.image;
3507-
fz_buffer *buf = NULL, *freebuf = NULL;
3507+
fz_buffer *buf = NULL, *freebuf = NULL; *mask_buf = NULL;
35083508
fz_compressed_buffer *buffer = fz_compressed_image_buffer(ctx, image);
35093509
fz_var(buf);
35103510
fz_var(freebuf);
3511+
fz_var(mask_buf);
35113512
int n = fz_colorspace_n(ctx, image->colorspace);
35123513
int w = image->w;
35133514
int h = image->h;
@@ -3539,10 +3540,8 @@ void JM_make_image_block(fz_stext_block *block, PyObject *block_dict)
35393540
}
35403541
bytes = JM_BinFromBuffer(buf);
35413542
if (image->mask) {
3542-
fz_buffer *mask = fz_new_buffer_from_image_as_png(ctx, image->mask, fz_default_color_params);
3543+
mask_buf = fz_new_buffer_from_image_as_png(ctx, image->mask, fz_default_color_params);
35433544
mask_bytes = JM_BinFromBuffer(mask);
3544-
fz_drop_buffer(ctx, mask);
3545-
35463545
} else {
35473546
mask_bytes = Py_BuildValue("s", NULL);
35483547
}
@@ -3570,7 +3569,7 @@ void JM_make_image_block(fz_stext_block *block, PyObject *block_dict)
35703569
Py_BuildValue("n", PyBytes_Size(bytes)));
35713570
DICT_SETITEM_DROP(block_dict, dictkey_image, bytes);
35723571
DICT_SETITEMSTR_DROP(block_dict, "mask", mask_bytes);
3573-
3572+
fz_drop_buffer(ctx, mask_buf);
35743573
fz_drop_buffer(ctx, freebuf);
35753574
}
35763575
fz_catch(ctx) {;}

0 commit comments

Comments
 (0)