[graphics/okular] core: fix: resolve ScriptAction memory leak in openDocument

Albert Astals Cid <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 3481e02b5f2b0e1ad22949b5c344e0bf1e49ca4e by Albert Astals Cid, on behalf of zhang shoucheng.
Committed on 18/07/2026 at 14:04.
Pushed by aacid into branch 'master'.

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.

M  +2    -2    core/document.cpp

https://invent.kde.org/graphics/okular/-/commit/3481e02b5f2b0e1ad22949b5c344e0bf1e49ca4e

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);
         }
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.