From f88398b6ac6a33209d551f676d73cec30ab2fc6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 15 Sep 2008 20:09:15 +0000 Subject: [PATCH] * GrepWindow::_AreAllFoldersOpenInTracker() could still leak entry_refs, even in not unlikely situations. * GrepWindow::_SelectFilesInTracker() was still leaking entry_refs in the success code path. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27577 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/text_search/GrepWindow.cpp | 44 ++++++++++++----------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/apps/text_search/GrepWindow.cpp b/src/apps/text_search/GrepWindow.cpp index cd1209edc3..41c261f853 100644 --- a/src/apps/text_search/GrepWindow.cpp +++ b/src/apps/text_search/GrepWindow.cpp @@ -1723,18 +1723,13 @@ GrepWindow::_AreAllFoldersOpenInTracker(BList *folderList) sendMessage.AddSpecifier("Window", count); status = trackerMessenger.SendMessage(&sendMessage, &replyMessage); - if (status != B_OK) return false; - entry_ref *tracker_ref = new entry_ref; - status = replyMessage.FindRef("result", tracker_ref); - - if (status == B_OK) - windowList.AddItem(static_cast(tracker_ref)); - - if (status != B_OK) { - delete tracker_ref; + entry_ref* trackerRef = new (nothrow) entry_ref; + status = replyMessage.FindRef("result", trackerRef); + if (status != B_OK || !windowList.AddItem(trackerRef)) { + delete trackerRef; break; } } @@ -1747,11 +1742,13 @@ GrepWindow::_AreAllFoldersOpenInTracker(BList *folderList) entry_ref* windowRef; BString folderString; BString windowString; + bool result = false; - if (folderCount > windowCount) + if (folderCount > windowCount) { // at least one folder is not open in Tracker - return false; - + goto out; + } + // Loop over the two lists and see if all folders exist as window for (int32 x = 0; x < folderCount; x++) { for (int32 y = 0; y < windowCount; y++) { @@ -1782,16 +1779,14 @@ GrepWindow::_AreAllFoldersOpenInTracker(BList *folderList) } } + result = found == folderCount; + +out: // delete list of window entry_refs for (int32 x = 0; x < windowCount; x++) delete static_cast(windowList.ItemAt(x)); - windowList.MakeEmpty(); - - if (found == folderCount) - return true; - - return false; + return result; } @@ -1829,13 +1824,10 @@ GrepWindow::_SelectFilesInTracker(BList* folderList, BMessage* refsMessage) if (status != B_OK) return status; - entry_ref *windowRef = new entry_ref; - status = windowReplyMessage.FindRef("result", windowRef); - - if (status != B_OK) { - delete windowRef; + entry_ref windowRef; + status = windowReplyMessage.FindRef("result", &windowRef); + if (status != B_OK) break; - } int32 folderCount = folderList->CountItems(); @@ -1851,7 +1843,7 @@ GrepWindow::_SelectFilesInTracker(BList* folderList, BMessage* refsMessage) BPath windowPath; BString windowString; - status = windowEntry.SetTo(windowRef); + status = windowEntry.SetTo(&windowRef); if (status != B_OK) break; @@ -1877,7 +1869,7 @@ GrepWindow::_SelectFilesInTracker(BList* folderList, BMessage* refsMessage) if (status != B_OK) break; - BDirectory directory(windowRef); + BDirectory directory(&windowRef); BEntry entry(&ref); if (directory.Contains(&entry)) selectionSendMessage.AddRef("data", &ref);