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. */
/* Clean up. */
if (!anim)
WebPFree (decoded);
- if (NILP (specified_data))
+ if (NILP (specified_data) && !anim)
xfree (contents);
return true;