Avoid creating a new QMimeData each time the Android clipboard is used

This patch aims to fix a memory leak that occurs when the platform
clipboard is used on Android. The QMimeData from the clipboard is
recreated each time mimeData is called

[ChangeLog][QtCore][QPA/Android] Fixed a memory leak in the clipboard

Task-number: QTBUG-36025
Change-Id: I241f586589ff256885caee5e5f737313d24d942d
Reviewed-by: BogDan Vatra <bogdan@kde.org>
This commit is contained in:
Samuel Gaist 2014-02-20 23:26:59 +01:00 committed by The Qt Project
parent c5b2425e8e
commit 736d7a26cd
2 changed files with 6 additions and 4 deletions

View File

@ -42,7 +42,6 @@
#include "qandroidplatformclipboard.h"
#include "androidjniclipboard.h"
#ifndef QT_NO_CLIPBOARD
#include <QMimeData>
QT_BEGIN_NAMESPACE
@ -56,9 +55,8 @@ QMimeData *QAndroidPlatformClipboard::mimeData(QClipboard::Mode mode)
if (QClipboard::Clipboard != mode || !QtAndroidClipboard::hasClipboardText())
return 0;
QMimeData *mimeData = new QMimeData();
mimeData->setText(QtAndroidClipboard::clipboardText());
return mimeData;
m_mimeData.setText(QtAndroidClipboard::clipboardText());
return &m_mimeData;
}
void QAndroidPlatformClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode)

View File

@ -43,6 +43,7 @@
#define QANDROIDPLATFORMCLIPBOARD_H
#include <qpa/qplatformclipboard.h>
#include <QMimeData>
#ifndef QT_NO_CLIPBOARD
QT_BEGIN_NAMESPACE
@ -55,6 +56,9 @@ public:
virtual QMimeData *mimeData(QClipboard::Mode mode = QClipboard::Clipboard);
virtual void setMimeData(QMimeData *data, QClipboard::Mode mode = QClipboard::Clipboard);
virtual bool supportsMode(QClipboard::Mode mode) const;
private:
QMimeData m_mimeData;
};
QT_END_NAMESPACE