emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 9b892eeb91: Fix webp_load data lifetime issues


From: Lars Ingebrigtsen
Subject: master 9b892eeb91: Fix webp_load data lifetime issues
Date: Tue, 12 Apr 2022 10:09:04 -0400 (EDT)

branch: master
commit 9b892eeb918a7416a62506f4c618a9de75e99165
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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.
---
 src/image.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/image.c b/src/image.c
index 3afb832407..530819eab9 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;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]