Fix crash when holding on unsupported image

pull/2659/head
poire-z 7 years ago committed by Qingping Hou
parent ee0e337433
commit 112e6a46e4

@ -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

Loading…
Cancel
Save