[haiku-commits] Change in haiku[master]: LayoutBuilder.h: Fix use after free

  • From: Gerrit <review@xxxxxxxxxxxxxxxxxxx>
  • To: waddlesplash <waddlesplash@xxxxxxxxx>, haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 15 Nov 2020 02:11:13 +0000

From Murai Takashi <tmurai01@xxxxxxxxx>:

Murai Takashi has uploaded this change for review. ( 
https://review.haiku-os.org/c/haiku/+/3392 ;)


Change subject: LayoutBuilder.h: Fix use after free
......................................................................

LayoutBuilder.h: Fix use after free

Fix 'item' is used after delete.
Pointed out by Clang Static Analyzer.

Change-Id: I8eca3084c97b37015a2da1b96119a458d4eb9aa7
---
M headers/os/interface/LayoutBuilder.h
1 file changed, 6 insertions(+), 2 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/92/3392/1

diff --git a/headers/os/interface/LayoutBuilder.h 
b/headers/os/interface/LayoutBuilder.h
index 4ba372c..3601369 100644
--- a/headers/os/interface/LayoutBuilder.h
+++ b/headers/os/interface/LayoutBuilder.h
@@ -1737,8 +1737,10 @@
        char shortcut, uint32 modifiers)
 {
        BMenuItem* item = new BMenuItem(label, message, shortcut, modifiers);
-       if (!fMenu->AddItem(item))
+       if (!fMenu->AddItem(item)) {
                delete item;
+               item = NULL;
+       }

        return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
 }
@@ -1758,8 +1760,10 @@
                throw;
        }

-       if (!fMenu->AddItem(item))
+       if (!fMenu->AddItem(item)) {
                delete item;
+               item = NULL;
+       }

        return MenuItem<ParentBuilder>(this->fParent, fMenu, item);
 }

--
To view, visit https://review.haiku-os.org/c/haiku/+/3392
To unsubscribe, or for help writing mail filters, visit 
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I8eca3084c97b37015a2da1b96119a458d4eb9aa7
Gerrit-Change-Number: 3392
Gerrit-PatchSet: 1
Gerrit-Owner: Murai Takashi <tmurai01@xxxxxxxxx>
Gerrit-MessageType: newchange

Other related posts:

  • » [haiku-commits] Change in haiku[master]: LayoutBuilder.h: Fix use after free - Gerrit