summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-04-12 16:08:50 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-04-12 16:08:58 +0200
commit9b892eeb918a7416a62506f4c618a9de75e99165 (patch)
tree1def71c642b29db5b4ae7f3240b5b9cf8187c62c
parentc3c08b90b67ba42be06a260718c5b6e5939e0b25 (diff)
downloademacs-9b892eeb918a7416a62506f4c618a9de75e99165.tar.gz
Fix webp_load data lifetime issues
* src/image.c (webp_load): Take care of lifetime issues of the image data we're iterating over for animated images.
-rw-r--r--src/image.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/image.c b/src/image.c
index 3afb8324078..530819eab9d 100644
--- a/src/image.c
+++ b/src/image.c
@@ -9525,7 +9525,19 @@ webp_load (struct frame *f, struct image *img)
WebPAnimDecoderDelete (cache->handle);
WebPData webp_data;
- webp_data.bytes = contents;
+ if (NILP (specified_data))
+ /* If we got the data from a file, then we don't need to
+ copy the data. */
+ webp_data.bytes = cache->temp = contents;
+ else
+ /* We got the data from a string, so copy it over so that
+ it doesn't get garbage-collected. */
+ {
+ webp_data.bytes = xmalloc (size);
+ memcpy ((void*) webp_data.bytes, contents, size);
+ }
+ /* In any case, we release the allocated memory when we
+ purge the anim cache. */
webp_data.size = size;
/* Get the width/height of the total image. */
@@ -9662,7 +9674,7 @@ webp_load (struct frame *f, struct image *img)
/* Clean up. */
if (!anim)
WebPFree (decoded);
- if (NILP (specified_data))
+ if (NILP (specified_data) && !anim)
xfree (contents);
return true;