servers/app: Fix double delete

Pointed out by Clang Static Analyzer.

Change-Id: Ifba9ffd03a49fd66cc3e3c7cacaee641b7e939ab
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3774
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Murai Takashi 2021-03-13 09:05:54 +09:00 committed by Adrien Destugues
parent 3592432e9b
commit 741032ea6d

View File

@ -68,7 +68,7 @@ ScreenChangeListener::ScreenChanged(HWInterface* interface)
ScreenManager::ScreenManager() ScreenManager::ScreenManager()
: :
BLooper("screen manager"), BLooper("screen manager"),
fScreenList(4) fScreenList(4, true)
{ {
_ScanDrivers(); _ScanDrivers();
@ -82,11 +82,6 @@ ScreenManager::ScreenManager()
ScreenManager::~ScreenManager() ScreenManager::~ScreenManager()
{ {
for (int32 i = 0; i < fScreenList.CountItems(); i++) {
screen_item* item = fScreenList.ItemAt(i);
delete item;
}
} }
@ -218,8 +213,9 @@ ScreenManager::_ScanDrivers()
ScreenManager::screen_item* ScreenManager::screen_item*
ScreenManager::_AddHWInterface(HWInterface* interface) ScreenManager::_AddHWInterface(HWInterface* interface)
{ {
Screen* screen = new(nothrow) Screen(interface, fScreenList.CountItems()); ObjectDeleter<Screen> screen(
if (screen == NULL) { new(nothrow) Screen(interface, fScreenList.CountItems()));
if (!screen.IsSet()) {
delete interface; delete interface;
return NULL; return NULL;
} }
@ -230,10 +226,10 @@ ScreenManager::_AddHWInterface(HWInterface* interface)
screen_item* item = new(nothrow) screen_item; screen_item* item = new(nothrow) screen_item;
if (item != NULL) { if (item != NULL) {
item->screen.SetTo(screen); item->screen.SetTo(screen.Detach());
item->owner = NULL; item->owner = NULL;
item->listener.SetTo( item->listener.SetTo(
new(nothrow) ScreenChangeListener(*this, screen)); new(nothrow) ScreenChangeListener(*this, item->screen.Get()));
if (item->listener.IsSet() if (item->listener.IsSet()
&& interface->AddListener(item->listener.Get())) { && interface->AddListener(item->listener.Get())) {
if (fScreenList.AddItem(item)) if (fScreenList.AddItem(item))
@ -246,7 +242,6 @@ ScreenManager::_AddHWInterface(HWInterface* interface)
} }
} }
delete screen;
return NULL; return NULL;
} }
@ -263,4 +258,3 @@ ScreenManager::MessageReceived(BMessage* message)
BHandler::MessageReceived(message); BHandler::MessageReceived(message);
} }
} }