From ecf9f948002cda853199de279dde5255737e4124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 11 Mar 2006 19:32:53 +0000 Subject: [PATCH] * cleaned up fPulseRunner stuff, I have no idea why fPulseEnabled was useful... so I removed it * fixed memory leak with SetPulseRate(0), fPulseRunner is now properly freed in the Window destructor * fTitle is now freed as well * fix some potential leaks in BView destructor as well I wrote a stress test app, which I'm soon going to commit as well... it shows that not all memory leaks are fixed by this patch, I could use some help with this... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16713 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/Window.h | 4 ++-- src/kits/interface/View.cpp | 9 ++++----- src/kits/interface/Window.cpp | 34 ++++++++++++++-------------------- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/headers/os/interface/Window.h b/headers/os/interface/Window.h index d5c5edcaa0..885660ca53 100644 --- a/headers/os/interface/Window.h +++ b/headers/os/interface/Window.h @@ -318,7 +318,7 @@ private: BButton *fDefaultButton; BList fShortcuts; int32 fTopViewToken; - bool fPulseEnabled; + bool _unused2; // was fPulseEnabled bool fViewsNeedPulse; // not yet used bool fIsFilePanel; bool fMaskActivated; @@ -326,7 +326,7 @@ private: bool fWaitingForMenu; bool fMinimized; bool fNoQuitShortcut; - bool _unused2; + bool _unused3; sem_id fMenuSem; float fMaxZoomHeight; float fMaxZoomWidth; diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index ecd9464ad4..c57b8d5012 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -565,6 +565,7 @@ BView::~BView() SetName(NULL); + removeCommArray(); delete fState; } @@ -809,7 +810,7 @@ BView::SetFlags(uint32 flags) if (fOwner) { if (flags & B_PULSE_NEEDED) { check_lock_no_pick(); - if (!fOwner->fPulseEnabled) + if (fOwner->fPulseRunner == NULL) fOwner->SetPulseRate(500000); } @@ -2996,9 +2997,7 @@ BView::EndLineArray() _FlushIfNotInTransaction(); - delete [] comm->array; - delete comm; - comm = NULL; + removeCommArray(); } @@ -4120,7 +4119,7 @@ BView::_Attach() if (fOwner) { if (fFlags & B_PULSE_NEEDED) { check_lock_no_pick(); - if (!fOwner->fPulseEnabled) + if (fOwner->fPulseRunner == NULL) fOwner->SetPulseRate(500000); } } diff --git a/src/kits/interface/Window.cpp b/src/kits/interface/Window.cpp index 3226153efa..5065b020fb 100644 --- a/src/kits/interface/Window.cpp +++ b/src/kits/interface/Window.cpp @@ -326,6 +326,7 @@ BWindow::~BWindow() } // TODO: release other dynamically-allocated objects + free(fTitle); // Deleting this semaphore will tell open menus to quit. if (fMenuSem > 0) @@ -960,7 +961,7 @@ FrameMoved(origin); } case B_PULSE: - if (target == this && fPulseEnabled) { + if (target == this && fPulseRunner) { fTopView->_Pulse(); fLink->Flush(); } else @@ -1332,28 +1333,23 @@ void BWindow::SetPulseRate(bigtime_t rate) { // TODO: What about locking?!? - if (rate < 0) + if (rate < 0 || rate == fPulseRate) return; - // ToDo: isn't fPulseRunner enough? Why fPulseEnabled? - if (fPulseRate == 0 && !fPulseEnabled) { - fPulseRunner = new BMessageRunner(BMessenger(this), - new BMessage(B_PULSE), rate); - fPulseRate = rate; - fPulseEnabled = true; - return; - } + fPulseRate = rate; - if (rate == 0 && fPulseEnabled) { + if (rate > 0) { + if (fPulseRunner == NULL) { + fPulseRunner = new BMessageRunner(BMessenger(this), + new BMessage(B_PULSE), rate); + } else { + fPulseRunner->SetInterval(rate); + } + } else { + // rate == 0 delete fPulseRunner; fPulseRunner = NULL; - - fPulseRate = rate; - fPulseEnabled = false; - return; } - - fPulseRunner->SetInterval(rate); } @@ -2199,7 +2195,6 @@ BWindow::_InitData(BRect frame, const char* title, window_look look, AddShortcut('V', B_COMMAND_KEY, new BMessage(B_PASTE), NULL); AddShortcut('A', B_COMMAND_KEY, new BMessage(B_SELECT_ALL), NULL); - fPulseEnabled = false; fPulseRate = 0; fPulseRunner = NULL; @@ -2234,6 +2229,7 @@ BWindow::_InitData(BRect frame, const char* title, window_look look, port_id receivePort = create_port(B_LOOPER_PORT_DEFAULT_CAPACITY, "w