[utilities/kaichat] src/plugins/text/sharetext: Don't try to write when we are not able to open.

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit ccf148e60093bc42e5aaf91418b1f8e8cd822781 by Laurent Montel.
Committed on 16/08/2026 at 05:25.
Pushed by mlaurent into branch 'master'.

Don't try to write when we are not able to open.

Set permission after writing

M  +4    -1    src/plugins/text/sharetext/purposemenuwidget.cpp

https://invent.kde.org/utilities/kaichat/-/commit/ccf148e60093bc42e5aaf91418b1f8e8cd822781

diff --git a/src/plugins/text/sharetext/purposemenuwidget.cpp b/src/plugins/text/sharetext/purposemenuwidget.cpp
index 8b2563d..64f90f4 100644
--- a/src/plugins/text/sharetext/purposemenuwidget.cpp
+++ b/src/plugins/text/sharetext/purposemenuwidget.cpp
@@ -50,9 +50,12 @@ void PurposeMenuWidget::slotInitializeShareMenu()
     mTemporaryShareFile = new QTemporaryFile();
     if (!mTemporaryShareFile->open()) {
         qWarning() << "Impossible to open temporary file";
+        delete mTemporaryShareFile;
+        mTemporaryShareFile = nullptr;
+        return;
     }
-    mTemporaryShareFile->setPermissions(QFile::ReadUser);
     mTemporaryShareFile->write(text());
+    mTemporaryShareFile->setPermissions(QFile::ReadUser);
     mTemporaryShareFile->close();
     mShareMenu->model()->setInputData(
         QJsonObject{{u"urls"_s, QJsonArray{{QUrl::fromLocalFile(mTemporaryShareFile->fileName()).toString()}}}, {u"mimeType"_s, {u"text/plain"_s}}});
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.