Fix PDFium abuse that leads to a crash on Windows ARM (#3460)

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel
2025-02-04 17:29:01 -05:00
committed by GitHub
parent 8c9f26e249
commit 014bf67c63
4 changed files with 11 additions and 7 deletions

View File

@@ -1209,7 +1209,6 @@ public:
FPDF_ClosePage(m_page);
if (m_doc)
FPDF_CloseDocument(m_doc);
FPDF_DestroyLibrary();
}
int page() const override { return m_currentPage; }
@@ -1224,7 +1223,7 @@ private:
return std::nullopt;
if (m_page)
FPDF_ClosePage(m_page);
FPDF_ClosePage(std::exchange(m_page, nullptr));
m_page = FPDF_LoadPage(m_doc, m_currentPage++);
if (!m_page)
throw std::runtime_error("Failed to load page.");

View File

@@ -181,5 +181,9 @@ int main(int argc, char *argv[])
// Otherwise, we can get a heap-use-after-free inside of llama.cpp.
ChatListModel::globalInstance()->destroyChats();
#ifndef GPT4ALL_USE_QTPDF
FPDF_DestroyLibrary();
#endif
return res;
}