diff --git a/src/plugins/cpaster/cpasterplugin.cpp b/src/plugins/cpaster/cpasterplugin.cpp
index 47cbf0091bbdd747ffb384e14f63aaa765171dbe..e3a17c01d983e567e9935c230edbbece68a5ee46 100644
--- a/src/plugins/cpaster/cpasterplugin.cpp
+++ b/src/plugins/cpaster/cpasterplugin.cpp
@@ -351,6 +351,8 @@ void CodepasterPlugin::finishFetch(const QString &titleDescription,
     // Keep the file and store in list of files to be removed.
     tempFile->setAutoRemove(false);
     const QString fileName = tempFile->fileName();
+    // Discard to temporary file to make sure it is closed and no changes are triggered.
+    tempFile = TemporaryFilePtr();
     m_fetchedSnippets.push_back(fileName);
     // Open editor with title.
     Core::IEditor* editor = EditorManager::instance()->openEditor(fileName);