BookInfoManager: Actually close the document after extraction

DocumentRegistry just decreases a ref, it doesn't close anything.

Plug the same Document leak in a few other places, and document this.
reviewable/pr7711/r1
NiLuJe 3 years ago
parent e70bc60f0f
commit 94f708b53b

@ -126,7 +126,7 @@ function BookInfo:show(file, book_props)
book_props = document:getProps() book_props = document:getProps()
book_props.pages = pages book_props.pages = pages
end end
DocumentRegistry:closeDocument(file) document:close()
end end
end end
@ -219,7 +219,7 @@ function BookInfo:show(file, book_props)
fullscreen = true, fullscreen = true,
} }
end end
DocumentRegistry:closeDocument(file) document:close()
end end
if not widget then if not widget then
widget = InfoMessage:new{ widget = InfoMessage:new{

@ -91,6 +91,7 @@ function Document:unlock(password)
end end
-- this might be overridden by a document implementation -- this might be overridden by a document implementation
-- (in which case, do make sure it calls this one, too, to avoid refcounting mismatches in DocumentRegistry!)
function Document:close() function Document:close()
local DocumentRegistry = require("document/documentregistry") local DocumentRegistry = require("document/documentregistry")
if self.is_open then if self.is_open then

@ -191,6 +191,7 @@ function DocumentRegistry:mimeToExt(mimetype)
return self.mimetype_ext[mimetype] return self.mimetype_ext[mimetype]
end end
--- Returns a new Document instance on success
function DocumentRegistry:openDocument(file, provider) function DocumentRegistry:openDocument(file, provider)
-- force a GC, so that any previous document used memory can be reused -- force a GC, so that any previous document used memory can be reused
-- immediately by this new document without having to wait for the -- immediately by this new document without having to wait for the
@ -219,6 +220,8 @@ function DocumentRegistry:openDocument(file, provider)
end end
end end
--- Does *NOT* finalize a Document instance, call its :close() instead if that's what you're looking for!
--- (i.e., nothing but Document:close should call this!)
function DocumentRegistry:closeDocument(file) function DocumentRegistry:closeDocument(file)
if self.registry[file] then if self.registry[file] then
self.registry[file].refs = self.registry[file].refs - 1 self.registry[file].refs = self.registry[file].refs - 1

@ -544,7 +544,7 @@ function BookInfoManager:extractBookInfo(filepath, cover_specs)
end end
end end
end end
DocumentRegistry:closeDocument(filepath) document:close()
else else
loaded = false loaded = false
end end

@ -335,7 +335,7 @@ function CoverMenu:updateItems(select_number)
}) })
end end
UIManager:close(self.file_dialog) UIManager:close(self.file_dialog)
DocumentRegistry:closeDocument(file) document:close()
end end
end, end,
}, },
@ -468,7 +468,7 @@ function CoverMenu:onHistoryMenuHold(item)
}) })
end end
UIManager:close(self.histfile_dialog) UIManager:close(self.histfile_dialog)
DocumentRegistry:closeDocument(file) document:close()
end end
end, end,
}, },
@ -590,7 +590,7 @@ function CoverMenu:onCollectionsMenuHold(item)
}) })
end end
UIManager:close(self.collfile_dialog) UIManager:close(self.collfile_dialog)
DocumentRegistry:closeDocument(file) document:close()
end end
end, end,
}, },

Loading…
Cancel
Save