From 374d5a4c6df1a191b023c906459b9b51cc782e00 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Sat, 26 Nov 2011 21:11:51 -0500 Subject: [PATCH] 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 --- src/preferences/appearance/DecorSettingsView.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/preferences/appearance/DecorSettingsView.cpp b/src/preferences/appearance/DecorSettingsView.cpp index bbfdb165b9..c149c5ce78 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(); }