From 338fedd65a5bc57f3ec35b9c0d48ab5d8b013bd3 Mon Sep 17 00:00:00 2001 From: Zardshard <0azrune6@zard.anonaddy.com> Date: Wed, 31 May 2023 13:00:37 -0400 Subject: [PATCH] Tracker: Fix memory leak BMenuField's constructor (called on line 715) used to be passed fDirMenu. The constructor would create a new BMenuItem using fDirMenu. TFilePanel::Init did not want this menu so it removed it with a call to RemoveItem (located on line 721). This call, however, does not actually free the memory. It just removes it from the menu. The refactor that I did here fixes this by never creating the new BMenuItem in the first place. This is done by passing NULL into BMenuField's constructor instead of fDirMenu. It happens that the refactoring also cleans up TFilePanel::Init slightly. Change-Id: I05ef24f429fb309ff41806e342d275f832772b5e Reviewed-on: https://review.haiku-os.org/c/haiku/+/6486 Reviewed-by: waddlesplash --- src/kits/tracker/FilePanelPriv.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/kits/tracker/FilePanelPriv.cpp b/src/kits/tracker/FilePanelPriv.cpp index e2297e3e80..8e9955cf1c 100644 --- a/src/kits/tracker/FilePanelPriv.cpp +++ b/src/kits/tracker/FilePanelPriv.cpp @@ -699,8 +699,6 @@ TFilePanel::Init(const BMessage*) fBackView->AddChild(fMenuBar); // add directory menu and menufield - fDirMenu = new BDirMenu(0, this, kSwitchDirectory, "refs"); - font_height ht; be_plain_font->GetHeight(&ht); const float f_height = ht.ascent + ht.descent + ht.leading; @@ -712,16 +710,14 @@ TFilePanel::Init(const BMessage*) rect.right = rect.left + (spacing * 50); rect.bottom = rect.top + (f_height > 22 ? f_height : 22); - fDirMenuField = new BMenuField(rect, "DirMenuField", "", fDirMenu); + fDirMenuField = new BMenuField(rect, "DirMenuField", "", NULL); fDirMenuField->MenuBar()->SetFont(be_plain_font); fDirMenuField->SetDivider(0); fDirMenuField->MenuBar()->SetMaxContentWidth(rect.Width() - 26.0f); // Make room for the icon - fDirMenuField->MenuBar()->RemoveItem((int32)0); - fDirMenu->SetMenuBar(fDirMenuField->MenuBar()); - // the above is a weird call from BDirMenu - // ToDo: clean up + fDirMenu = new BDirMenu(fDirMenuField->MenuBar(), + this, kSwitchDirectory, "refs"); BEntry entry(TargetModel()->EntryRef()); if (entry.InitCheck() == B_OK)