From 4a461e25073cc5ff858a77236aab19c25bc4bf39 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 30 Jan 2019 04:18:49 +0000 Subject: [PATCH] fix data return from heifsave_buffer --- libvips/foreign/heifsave.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libvips/foreign/heifsave.c b/libvips/foreign/heifsave.c index 9e85cc9a..f813b6ff 100644 --- a/libvips/foreign/heifsave.c +++ b/libvips/foreign/heifsave.c @@ -481,10 +481,14 @@ vips_foreign_save_heif_buffer_write( struct heif_context *ctx, VipsBlob *blob; struct heif_error error; + void *data_copy; - /* FIXME .. argh do we need to memcpy()? + /* FIXME .. we have to memcpy()! */ - blob = vips_blob_new( (VipsCallbackFn) g_free, data, length ); + data_copy = vips_malloc( NULL, length ); + memcpy( data_copy, data, length ); + + blob = vips_blob_new( (VipsCallbackFn) vips_free, data_copy, length ); g_object_set( heif, "buffer", blob, NULL ); vips_area_unref( VIPS_AREA( blob ) ); @@ -498,7 +502,8 @@ vips_foreign_save_heif_buffer_build( VipsObject *object ) { VipsForeignSaveHeif *heif = (VipsForeignSaveHeif *) object; - /* FIXME ... argh, allocating on the stack! + /* FIXME ... argh, allocating on the stack! But the example code does + * this too. */ struct heif_writer writer; struct heif_error error;