path: root/src/gui/kernel/qclipboard.cpp
diff options
authorEskil Abrahamsen Blomfeldt <>2014-10-09 12:46:04 +0200
committerEskil Abrahamsen Blomfeldt <>2014-10-10 13:37:59 +0200
commit74a20b77a67ec4d5a8be0f59302075d34151dc05 (patch)
treed9ac556372caf03b6b56801f15402424d9c5d597 /src/gui/kernel/qclipboard.cpp
parent9685c72e37d618cf44aa15c892375b3c8d27e578 (diff)
Fix memory leak in QClipboard::setMimeData()
The setMimeData() function is documented to take ownership of the object passed in, but in the case where the platform plugin did not support the requested mode, we would simply return without deleting the object nor telling the application, so it would cause a potential memory leak. We need to honor the contract, even when we fail to set the mime data. Test was updated to avoid verifying the leak in cases where the platform does not support all modes. [ChangeLog][QtGui][Clipboard] Fixed a memory leak in setMimeData() when the platform plugin did not support the requested mode. Task-number: QTBUG-41852 Change-Id: I2112da1613199fe1b56724e7ccf097b9e912c117 Reviewed-by: Richard Moe Gustavsen <>
Diffstat (limited to 'src/gui/kernel/qclipboard.cpp')
1 files changed, 8 insertions, 3 deletions
diff --git a/src/gui/kernel/qclipboard.cpp b/src/gui/kernel/qclipboard.cpp
index ec9a8fdcf0..5be9f19b3e 100644
--- a/src/gui/kernel/qclipboard.cpp
+++ b/src/gui/kernel/qclipboard.cpp
@@ -463,9 +463,14 @@ const QMimeData* QClipboard::mimeData(Mode mode) const
void QClipboard::setMimeData(QMimeData* src, Mode mode)
QPlatformClipboard *clipboard = QGuiApplicationPrivate::platformIntegration()->clipboard();
- if (!clipboard->supportsMode(mode)) return;
- clipboard->setMimeData(src,mode);
+ if (!clipboard->supportsMode(mode)) {
+ if (src != 0) {
+ qWarning("Data set on unsupported clipboard mode. QMimeData object will be deleted.");
+ src->deleteLater();
+ }
+ } else {
+ clipboard->setMimeData(src,mode);
+ }