[haiku-commits] haiku: hrev43330 - src/preferences/appearance

  • From: stpere@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 27 Nov 2011 03:15:46 +0100 (CET)

hrev43330 adds 1 changeset to branch 'master'
old head: 36e1394ccf04e61dec6f591161f0f219c1abd48a
new head: 374d5a4c6df1a191b023c906459b9b51cc782e00

----------------------------------------------------------------------------

1 files changed, 6 insertions(+), 7 deletions(-)
src/preferences/appearance/DecorSettingsView.cpp |   13 ++++++-------

############################################################################

Revision:    hrev43330
Commit:      374d5a4c6df1a191b023c906459b9b51cc782e00
URL:         http://cgit.haiku-os.org/haiku/commit/?id=374d5a4
Author:      Philippe Saint-Pierre <stpere@xxxxxxxxx>
Date:        Sun Nov 27 02:11:51 2011 UTC

Fix possible resource leakage and NULL dereference

* Use the std::nothrow behaviour of operator new
* Avoid to compare the CurrentDecorator at every iteration
* Avoid possible NULL dereference

Fix CID 10947 and CID 10889

----------------------------------------------------------------------------

diff --git a/src/preferences/appearance/DecorSettingsView.cpp 
b/src/preferences/appearance/DecorSettingsView.cpp
index bbfdb16..c149c5c 100644
--- a/src/preferences/appearance/DecorSettingsView.cpp
+++ b/src/preferences/appearance/DecorSettingsView.cpp
@@ -162,7 +162,7 @@ DecorSettingsView::_BuildDecorMenu()
        DecorInfo* decorator = NULL;
 
        // collect the current system decor settings
-       DecorInfoUtility* decorUtility = new DecorInfoUtility();
+       DecorInfoUtility* decorUtility = new(std::nothrow) DecorInfoUtility();
 
        if (decorUtility == NULL) {
                return;
@@ -174,21 +174,20 @@ DecorSettingsView::_BuildDecorMenu()
                if (decorator == NULL) {
                        fprintf(stderr, "Decorator : error NULL entry @ %li / 
%li\n",
                                i, count);
+                       continue;
                }
 
                BString decorName = decorator->Name();
 
-               if (decorUtility->CurrentDecorator() == decorator)
-                       fCurrentDecor = (char*)decorName.String();
-
                BMessage* message = new BMessage(kMsgSetDecor);
-               message->AddString("decor", decorator->Name());
+               message->AddString("decor", decorName);
 
-               BMenuItem* item
-                       = new BMenuItem(decorator->Name(), message);
+               BMenuItem* item = new BMenuItem(decorName, message);
 
                fDecorMenu->AddItem(item);
        }
+       fCurrentDecor = 
(char*)decorUtility->CurrentDecorator()->Name().String();
+       delete decorUtility;
 
        _SetCurrentDecor();
 }


Other related posts:

  • » [haiku-commits] haiku: hrev43330 - src/preferences/appearance - stpere