Description: Avoid a memory leak when webp file closed
 This patch restores some code removed in patch fix-animated-webp-loading
 which upstream have rebased on the current codebase
Author: NRK <nrk@distroot.org>
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1013149
Forwarded: not-needed
Applied-Upstream: https://codeberg.org/nsxiv/nsxiv/commit/b0b16f1d0ffa550a8358206de844c9cf13f94ada
Reviewed-by: Nick Morrott <nickm@debian.org>
Last-Update: 2022-08-11
---
--- a/image.c
+++ b/image.c
@@ -358,9 +358,9 @@
 	if ((err = fframe == NULL && img == NULL))
 		goto fail;
 
-	if ((err = (webp_file = fopen(file->path, "rb")) == NULL)) {
-		error(0, 0, "%s: Error opening webp image", file->name);
-		goto fail;
+	if ((webp_file = fopen(file->path, "rb")) == NULL) {
+		error(0, errno, "%s: Error opening webp image", file->name);
+		return false;
 	}
 	fseek(webp_file, 0L, SEEK_END);
 	data.size = ftell(webp_file);
@@ -445,6 +445,7 @@
 	if (dec != NULL)
 		WebPAnimDecoderDelete(dec);
 	free((unsigned char *)data.bytes);
+	fclose(webp_file);
 	return !err;
 }
 #endif /* HAVE_LIBWEBP */
