From 112e6a46e4a9c030487694f577370c5edd31a0f6 Mon Sep 17 00:00:00 2001 From: poire-z Date: Sun, 19 Mar 2017 16:10:27 +0100 Subject: [PATCH] Fix crash when holding on unsupported image --- frontend/document/credocument.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/frontend/document/credocument.lua b/frontend/document/credocument.lua index eee1f1dab..69e729612 100644 --- a/frontend/document/credocument.lua +++ b/frontend/document/credocument.lua @@ -162,8 +162,15 @@ function CreDocument:getImageFromPosition(pos) local Mupdf = require("ffi/mupdf") -- wrapped with pcall so we always free(data) local ok, image = pcall(Mupdf.renderImage, data, size) - ffi.C.free(data) -- need that explicite clean logger.dbg("Mupdf.renderImage", ok, image) + if not ok and string.find(image, "could not load image data: unknown image file format") then + -- in that case, mupdf seems to have already freed data (see mupdf/source/fitz/image.c:494), + -- as doing outselves ffi.C.free(data) would result in a crash with : + -- *** Error in `./luajit': double free or corruption (!prev): 0x0000000000e48a40 *** + logger.warn("Mupdf says 'unknown image file format', assuming mupdf has already freed image data") + else + ffi.C.free(data) -- need that explicite clean + end if ok then return image end