From f0a5d3162eefb3586d4398cd816cbe2bc0e93409 Mon Sep 17 00:00:00 2001 From: crs Date: Wed, 29 Dec 2004 17:06:00 +0000 Subject: [PATCH] Fixed leak of event objects on OS X. --- lib/platform/COSXEventQueueBuffer.cpp | 26 +++++++++++++------------- lib/platform/COSXEventQueueBuffer.h | 3 --- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/platform/COSXEventQueueBuffer.cpp b/lib/platform/COSXEventQueueBuffer.cpp index 76dcd35c..5bd0d747 100644 --- a/lib/platform/COSXEventQueueBuffer.cpp +++ b/lib/platform/COSXEventQueueBuffer.cpp @@ -34,7 +34,10 @@ COSXEventQueueBuffer::COSXEventQueueBuffer() : COSXEventQueueBuffer::~COSXEventQueueBuffer() { - setOSXEvent(NULL); + // release the last event + if (m_event != NULL) { + ReleaseEvent(m_event); + } } void @@ -47,10 +50,16 @@ COSXEventQueueBuffer::waitForEvent(double timeout) IEventQueueBuffer::Type COSXEventQueueBuffer::getEvent(CEvent& event, UInt32& dataID) { - EventRef carbonEvent = NULL; - OSStatus error = ReceiveNextEvent(0, NULL, 0.0, true, &carbonEvent); - setOSXEvent(carbonEvent); + // release the previous event + if (m_event != NULL) { + ReleaseEvent(m_event); + m_event = NULL; + } + // get the next event + OSStatus error = ReceiveNextEvent(0, NULL, 0.0, true, &m_event); + + // handle the event if (error == eventLoopQuitErr) { event = CEvent(CEvent::kQuit); return kSystem; @@ -113,12 +122,3 @@ COSXEventQueueBuffer::deleteTimer(CEventQueueTimer* timer) const { delete timer; } - -void -COSXEventQueueBuffer::setOSXEvent(EventRef event) -{ - if (m_event != NULL) { - ReleaseEvent(m_event); - } - m_event = RetainEvent(event); -} diff --git a/lib/platform/COSXEventQueueBuffer.h b/lib/platform/COSXEventQueueBuffer.h index b4910026..659b5940 100644 --- a/lib/platform/COSXEventQueueBuffer.h +++ b/lib/platform/COSXEventQueueBuffer.h @@ -33,9 +33,6 @@ public: newTimer(double duration, bool oneShot) const; virtual void deleteTimer(CEventQueueTimer*) const; -protected: - void setOSXEvent(EventRef event); - private: EventRef m_event; };