[graphics/okular/release/26.08] core: fix: resolve ScriptAction memory leak in openDocument
Albert Astals Cid <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 56a85cbb375818330506c784a58e9c1541de3c9a by Albert Astals Cid, on behalf of zhang shoucheng.
Committed on 18/07/2026 at 23:46.
Pushed by aacid into branch 'release/26.08'.
fix: resolve ScriptAction memory leak in openDocument
Replace heap-allocated ScriptAction with stack allocation,
since executeScriptEvent only borrows the pointer to read
scriptType/script values and does not take ownership.
Previously, every document with JS scripts would leak one
ScriptAction object (and its ScriptActionPrivate) per script
on each open.
(cherry picked from commit 3481e02b5f2b0e1ad22949b5c344e0bf1e49ca4e)
M +2 -2 core/document.cpp
https://invent.kde.org/graphics/okular/-/commit/56a85cbb375818330506c784a58e9c1541de3c9a
diff --git a/core/document.cpp b/core/document.cpp
index 9331475c6..dd1dc074b 100644
--- a/core/document.cpp
+++ b/core/document.cpp
@@ -2517,9 +2517,9 @@ Document::OpenResult Document::openDocument(const QString &docFile, const QUrl &
if (!docScripts.isEmpty()) {
d->m_scripter = new Scripter(d);
for (const QString &docscript : docScripts) {
- const Okular::ScriptAction *linkScript = new Okular::ScriptAction(Okular::JavaScript, docscript);
+ const Okular::ScriptAction linkScript(Okular::JavaScript, docscript);
std::shared_ptr<Event> event = Event::createDocEvent(Event::DocOpen);
- d->executeScriptEvent(event, linkScript);
+ d->executeScriptEvent(event, &linkScript);
}
}