Deskbar: Sanitize the usage of BMessage

... especially for SendMessage and SendReply.
* Delete the item's message if AddItem does not return successfully.
* Fixes #11934.

Signed-off-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Dario Casalinuovo 2015-04-09 16:22:37 +02:00 committed by Adrien Destugues
parent 9e11c3adb1
commit 0fc30d8934
5 changed files with 38 additions and 25 deletions

View File

@ -263,7 +263,8 @@ TBarView::MessageReceived(BMessage* message)
// so that I can follow the common pathway
// for adding icons to the tray
int32 id;
AddItem(new BMessage(*message), B_DESKBAR_TRAY, &id);
if (AddItem(message, B_DESKBAR_TRAY, &id) == B_OK)
Looper()->DetachCurrentMessage();
break;
}

View File

@ -39,6 +39,7 @@ All rights reserved.
#include <stdio.h>
#include <Application.h>
#include <AutoDeleter.h>
#include <Catalog.h>
#include <Directory.h>
#include <FindDirectory.h>
@ -516,15 +517,18 @@ TBarWindow::AddItem(BMessage* message)
BMessage reply;
status_t err = B_ERROR;
BMessage archivedView;
if (message->FindMessage("view", &archivedView) == B_OK) {
BMessage* archivedView = new BMessage();
ObjectDeleter<BMessage> deleter(archivedView);
if (message->FindMessage("view", archivedView) == B_OK) {
#if SHELF_AWARE
message->FindInt32("shelf", &shelf);
#endif
BMessage* archive = new BMessage(archivedView);
err = fBarView->AddItem(archive, shelf, &id);
if (err < B_OK)
delete archive;
err = fBarView->AddItem(archivedView, shelf, &id);
if (err == B_OK) {
// Detach the deleter since AddReplicant is taking ownership
// on success. This should be changed on server side.
deleter.Detach();
}
} else if (message->FindRef("addon", &ref) == B_OK) {
BEntry entry(&ref);
err = entry.InitCheck();

View File

@ -337,12 +337,12 @@ TReplicantTray::MessageReceived(BMessage* message)
bool showDayOfWeek = fTime->ShowDayOfWeek();
bool showTimeZone = fTime->ShowTimeZone();
BMessage* reply = new BMessage(kGetClockSettings);
reply->AddBool("showClock", showClock);
reply->AddBool("showSeconds", showSeconds);
reply->AddBool("showDayOfWeek", showDayOfWeek);
reply->AddBool("showTimeZone", showTimeZone);
message->SendReply(reply);
BMessage reply(kGetClockSettings);
reply.AddBool("showClock", showClock);
reply.AddBool("showSeconds", showSeconds);
reply.AddBool("showDayOfWeek", showDayOfWeek);
reply.AddBool("showTimeZone", showTimeZone);
message->SendReply(&reply);
break;
}
@ -451,9 +451,9 @@ TReplicantTray::ShowHideTime()
// Send a message to Time preferences telling it to update
BMessenger messenger("application/x-vnd.Haiku-Time");
BMessage* message = new BMessage(kShowHideTime);
message->AddBool("showClock", showClock);
messenger.SendMessage(message);
BMessage message(kShowHideTime);
message.AddBool("showClock", showClock);
messenger.SendMessage(&message);
}
@ -673,8 +673,9 @@ TReplicantTray::LoadAddOn(BEntry* entry, int32* id, bool addToSettings)
view->Archive(data);
delete view;
AddIcon(data, id, &ref);
// add the rep; adds info to list
// add the rep; adds info to list
if (AddIcon(data, id, &ref) != B_OK)
delete data;
if (addToSettings) {
fAddOnSettings.AddString(kReplicantPathField, path.Path());

View File

@ -195,8 +195,8 @@ TTimeView::MessageReceived(BMessage* message)
be_roster->Launch("application/x-vnd.Haiku-Time");
// tell Time preflet to switch to the clock tab
BMessenger messenger("application/x-vnd.Haiku-Time");
BMessage* switchToClock = new BMessage('SlCk');
messenger.SendMessage(switchToClock);
BMessage switchToClock('SlCk');
messenger.SendMessage(&switchToClock);
break;
}

View File

@ -16,6 +16,7 @@
#include <pthread.h>
#include <AutoDeleter.h>
#include <AutoLock.h>
#include <Beep.h>
#include <Dragger.h>
@ -1178,13 +1179,19 @@ BShelf::_InitData(BEntry *entry, BDataIO *stream, BView *view,
genCount = 1;
BMessage replicant;
BMessage *replmsg = NULL;
for (int32 i = 0; archive.FindMessage("replicant", i, &replicant) == B_OK; i++) {
for (int32 i = 0; archive.FindMessage("replicant", i, &replicant)
== B_OK; i++) {
BPoint point;
replmsg = new BMessage();
BMessage *replMsg = new BMessage();
ObjectDeleter<BMessage> deleter(replMsg);
replicant.FindPoint("position", &point);
replicant.FindMessage("message", replmsg);
AddReplicant(replmsg, point);
if (replicant.FindMessage("message", replMsg) == B_OK)
if (AddReplicant(replMsg, point) == B_OK) {
// Detach the deleter since AddReplicant is taking
// ownership on success. In R2 API this should be
// changed to take always ownership on the message.
deleter.Detach();
}
}
}
}