]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix webp_load data lifetime issues
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 12 Apr 2022 14:08:50 +0000 (16:08 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 12 Apr 2022 14:08:58 +0000 (16:08 +0200)
* src/image.c (webp_load): Take care of lifetime issues of the
image data we're iterating over for animated images.

src/image.c

index 3afb83240781e092bd87ff3cc1022e7187b831e7..530819eab9d7c0f6f55f6b28dbab72a7328377cd 100644 (file)
@@ -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;