From ced3755c30e6d91cb23175a888f32355401fe39d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 28 Mar 2008 11:40:55 +0000 Subject: [PATCH] * Fixed a memory leak in Deskbar's BarWindow.cpp when adding a deskbar replicant failed as pointed out by Mark Hellegers. * Clarified ownership of the passed in message in TReplicantTray::AddIcon() as well as BShelf::_AddReplicant(). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24621 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/deskbar/BarWindow.cpp | 5 ++++- src/apps/deskbar/StatusView.cpp | 24 ++++++++++++------------ src/kits/interface/Shelf.cpp | 8 ++++---- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/apps/deskbar/BarWindow.cpp b/src/apps/deskbar/BarWindow.cpp index 1a08fe24dc..00898a9d26 100644 --- a/src/apps/deskbar/BarWindow.cpp +++ b/src/apps/deskbar/BarWindow.cpp @@ -518,7 +518,10 @@ TBarWindow::AddItem(BMessage *message) #endif shelf = B_DESKBAR_TRAY; - err = fBarView->AddItem(new BMessage(archivedView), shelf, &id); + BMessage* archive = new BMessage(archivedView); + err = fBarView->AddItem(archive, shelf, &id); + if (err < B_OK) + delete archive; } else if (message->FindRef("addon", &ref) == B_OK) { // // exposing the name of the view here is not so great diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp index 4d330b0315..b7cd833a65 100644 --- a/src/apps/deskbar/StatusView.cpp +++ b/src/apps/deskbar/StatusView.cpp @@ -1022,15 +1022,15 @@ TReplicantTray::IconCount() const } -/** Message must contain an archivable view - * in the Archives folder for later rehydration - * returns the current boot id - */ - +/*! Message must contain an archivable view for later rehydration. + This function takes over ownership of the provided message on success + only. + Returns the current replicant ID. +*/ status_t -TReplicantTray::AddIcon(BMessage *icon, int32 *id, const entry_ref *addOn) +TReplicantTray::AddIcon(BMessage *archive, int32 *id, const entry_ref *addOn) { - if (!icon || !id) + if (archive == NULL || id == NULL) return B_ERROR; // find entry_ref @@ -1041,7 +1041,7 @@ TReplicantTray::AddIcon(BMessage *icon, int32 *id, const entry_ref *addOn) ref = *addOn; } else { const char *signature; - status_t status = icon->FindString("add_on", &signature); + status_t status = archive->FindString("add_on", &signature); if (status == B_OK) { BRoster roster; status = roster.FindApp(signature, &ref); @@ -1070,15 +1070,15 @@ TReplicantTray::AddIcon(BMessage *icon, int32 *id, const entry_ref *addOn) return status; *id = 999; - if (icon->what == B_ARCHIVED_OBJECT) - icon->what = 0; + if (archive->what == B_ARCHIVED_OBJECT) + archive->what = 0; - BRect originalBounds = icon->FindRect("_frame"); + BRect originalBounds = archive->FindRect("_frame"); // this is a work-around for buggy replicants that change their // size in AttachedToWindow() (such as "SVM") // !! check for name collisions? - status = fShelf->AddReplicant(icon, BPoint(1, 1)); + status = fShelf->AddReplicant(archive, BPoint(1, 1)); if (status != B_OK) return status; diff --git a/src/kits/interface/Shelf.cpp b/src/kits/interface/Shelf.cpp index 225f21d8b0..2a363ec559 100644 --- a/src/kits/interface/Shelf.cpp +++ b/src/kits/interface/Shelf.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007, Haiku. + * Copyright 2001-2008, Haiku. * Distributed under the terms of the MIT License. * * Authors: @@ -1052,7 +1052,7 @@ BShelf::_Archive(BMessage *data) const data->AddInt32("_sg_cnt", fGenCount); BMessage archive('ARCV'); - + for (int32 i = 0; i < fReplicants.CountItems(); i++) { if (((replicant_data *)fReplicants.ItemAt(i))->Archive(&archive) == B_OK) data->AddMessage("replicant", &archive); @@ -1161,6 +1161,7 @@ BShelf::_DeleteReplicant(replicant_data* item) } +//! Takes over ownership of \a data on success only status_t BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID) { @@ -1202,7 +1203,7 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID) } } } - + // Instantiate the object, if this fails we have a zombie image_id image; BArchivable *archivable = _InstantiateObject(data, &image); @@ -1221,7 +1222,6 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID) replicant = _GetReplicant(data, view, point, dragger, relation); if (replicant == NULL) return send_reply(data, B_ERROR, uniqueID); - } else if (fDisplayZombies && fAllowZombies) zombie = _CreateZombie(data, dragger);