goodreads(fix): double free

pull/2871/head
Qingping Hou 7 years ago committed by Frans de Jonge
parent 23c2955500
commit 3541320cd2

@ -301,6 +301,8 @@ function BookStatusWidget:genBookInfoGroup()
width = img_width,
height = img_height,
})
-- dereference thumbnail since we let imagewidget manages its lifecycle
self.thumbnail = nil
end
table.insert(book_info_group, CenterContainer:new{

@ -47,7 +47,9 @@ local InfoMessage = InputContainer:new{
timeout = nil, -- in seconds
width = nil, -- The width of the InfoMessage. Keep it nil to use default value.
height = nil, -- The height of the InfoMessage. If this field is set, a scrollbar may be shown.
image = nil, -- The image shows at the left of the InfoMessage.
-- The image shows at the left of the InfoMessage. Image data will be freed
-- by InfoMessage, caller should not manage its lifecycle
image = nil,
image_width = nil, -- The image width if image is used. Keep it nil to use original width.
image_height = nil, -- The image height if image is used. Keep it nil to use original height.
-- Whether the icon should be shown. If it is false, self.image will be ignored.
@ -76,6 +78,9 @@ function InfoMessage:init()
local image_widget
if self.show_icon then
-- TODO: remove self.image support, only used in filemanagersearch
-- this requires self.image's lifecycle to be managed by ImageWidget
-- instead of caller, which is easy to introduce bugs
if self.image then
image_widget = ImageWidget:new{
image = self.image,

@ -190,17 +190,19 @@ function GoodreadsBook:genBookInfoGroup()
align = "top",
HorizontalSpan:new{ width = split_span_width }
}
--thumbnail
-- thumbnail
local http = require("socket.http")
local body = http.request(self.dates.image)
local image = false
if body then image = Pic.openJPGDocumentFromMem(body) end
if image then
table.insert(book_info_group, ImageWidget:new{
image = image.image_bb,
image_disposable = false,
image = image.image_bb:copy(),
width = img_width,
height = img_height,
})
image:close()
else
table.insert(book_info_group, ImageWidget:new{
file = "resources/goodreadsnophoto.png",

Loading…
Cancel
Save