[directfb] Use QScopedPointer to manage heap allocated objects

Use QScopedPointer to avoid trying to manually delete objects. For
some of the cases the leak would only be viewable when things are
getting shut down. Leave in some more warnings for cleaning it up,
e.g. the m_eventBuffer of the Input is leaked and the input task will
only stop after another key event.

Change-Id: Ic54568343605b4ab7094a7dece40e22250184a37
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
This commit is contained in:
Holger Hans Peter Freyther 2011-09-18 22:04:09 +02:00 committed by Qt by Nokia
parent 9e54d1deab
commit acd09c21f7
7 changed files with 16 additions and 33 deletions

View File

@ -65,17 +65,12 @@ QDirectFbBackingStore::QDirectFbBackingStore(QWindow *window)
QDirectFbBlitter *blitter = new QDirectFbBlitter(window->size(), m_dfbSurface);
m_pmdata = new QDirectFbBlitterPlatformPixmap;
m_pmdata->setBlittable(blitter);
m_pixmap = new QPixmap(m_pmdata);
}
QDirectFbBackingStore::~QDirectFbBackingStore()
{
delete m_pixmap;
m_pixmap.reset(new QPixmap(m_pmdata));
}
QPaintDevice *QDirectFbBackingStore::paintDevice()
{
return m_pixmap;
return m_pixmap.data();
}
void QDirectFbBackingStore::flush(QWindow *, const QRegion &region, const QPoint &offset)

View File

@ -53,7 +53,6 @@ class QDirectFbBackingStore : public QPlatformBackingStore
{
public:
QDirectFbBackingStore(QWindow *window);
~QDirectFbBackingStore();
QPaintDevice *paintDevice();
void flush(QWindow *window, const QRegion &region, const QPoint &offset);
@ -66,9 +65,8 @@ public:
private:
void lockSurfaceToImage();
QPixmap *m_pixmap;
QScopedPointer<QPixmap> m_pixmap;
QBlittablePlatformPixmap *m_pmdata;
IDirectFBSurface *m_dfbSurface;
};

View File

@ -47,11 +47,9 @@ QDirectFBCursor::QDirectFBCursor(QPlatformScreen *screen)
: QPlatformCursor(screen)
{
QDirectFbConvenience::dfbInterface()->GetDisplayLayer(QDirectFbConvenience::dfbInterface(),DLID_PRIMARY, &m_layer);
m_image = new QPlatformCursorImage(0, 0, 0, 0, 0, 0);
m_image.reset(new QPlatformCursorImage(0, 0, 0, 0, 0, 0));
}
#warning "Memory leak?"
void QDirectFBCursor::changeCursor(QCursor *cursor, QWindow *)
{
int xSpot;

View File

@ -55,7 +55,7 @@ public:
private:
IDirectFBDisplayLayer *m_layer;
QPlatformCursorImage *m_image;
QScopedPointer<QPlatformCursorImage> m_image;
};
#endif // QDIRECTFBCURSOR_H

View File

@ -75,7 +75,7 @@ private:
IDirectFB *m_dfbInterface;
IDirectFBDisplayLayer *m_dfbDisplayLayer;
IDirectFBEventBuffer *m_eventBuffer;
IDirectFBEventBuffer *m_eventBuffer; // XXX: TODO: FIXME: leaked!!! (but it is a singleton)
bool m_shouldStop;
QSemaphore m_waitStop;

View File

@ -75,12 +75,7 @@ QDirectFbScreen::QDirectFbScreen(int display)
m_depth = QDirectFbConvenience::colorDepthForSurface(config.pixelformat);
m_physicalSize = QSizeF(config.width, config.height) * inch / dpi;
m_cursor = new QDirectFBCursor(this);
}
QDirectFbScreen::~QDirectFbScreen()
{
#warning "Delete the cursor?"
m_cursor.reset(new QDirectFBCursor(this));
}
QDirectFbIntegration::QDirectFbIntegration()
@ -111,18 +106,17 @@ QDirectFbIntegration::QDirectFbIntegration()
QDirectFbScreen *primaryScreen = new QDirectFbScreen(0);
screenAdded(primaryScreen);
m_inputRunner = new QThread;
m_input = new QDirectFbInput(0);
m_input->moveToThread(m_inputRunner);
QObject::connect(m_inputRunner,SIGNAL(started()),m_input,SLOT(runInputEventLoop()));
m_inputRunner.reset(new QThread);
m_input.reset(new QDirectFbInput(0));
m_input->moveToThread(m_inputRunner.data());
QObject::connect(m_inputRunner.data(), SIGNAL(started()),
m_input.data(), SLOT(runInputEventLoop()));
m_inputRunner->start();
}
QDirectFbIntegration::~QDirectFbIntegration()
{
m_input->stopInputEventLoop();
delete m_inputRunner;
delete m_input;
}
QPlatformPixmap *QDirectFbIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
@ -135,8 +129,7 @@ QPlatformPixmap *QDirectFbIntegration::createPlatformPixmap(QPlatformPixmap::Pix
QPlatformWindow *QDirectFbIntegration::createPlatformWindow(QWindow *window) const
{
QDirectFbInput *input = const_cast<QDirectFbInput *>(m_input);//gah
return new QDirectFbWindow(window,input);
return new QDirectFbWindow(window,m_input.data());
}
QAbstractEventDispatcher *QDirectFbIntegration::guiThreadEventDispatcher() const

View File

@ -58,7 +58,6 @@ class QDirectFbScreen : public QPlatformScreen
{
public:
QDirectFbScreen(int display);
~QDirectFbScreen();
QRect geometry() const { return m_geometry; }
int depth() const { return m_depth; }
@ -74,7 +73,7 @@ public:
IDirectFBDisplayLayer *m_layer;
private:
QDirectFBCursor *m_cursor;
QScopedPointer<QDirectFBCursor> m_cursor;
};
class QDirectFbIntegration : public QPlatformIntegration
@ -91,8 +90,8 @@ public:
QPlatformFontDatabase *fontDatabase() const;
private:
QDirectFbInput *m_input;
QThread *m_inputRunner;
QScopedPointer<QDirectFbInput> m_input;
QScopedPointer<QThread> m_inputRunner;
QPlatformFontDatabase *m_fontDb;
QAbstractEventDispatcher *m_eventDispatcher;
};