Shelf: Save() leaked a previous fStream. Untested.
Also, a few style-cleanups along the way.
This commit is contained in:
@@ -550,7 +550,7 @@ BShelf::~BShelf()
|
|||||||
Save();
|
Save();
|
||||||
|
|
||||||
// we own fStream only when fEntry is set
|
// we own fStream only when fEntry is set
|
||||||
if (fEntry) {
|
if (fEntry != NULL) {
|
||||||
delete fEntry;
|
delete fEntry;
|
||||||
delete fStream;
|
delete fStream;
|
||||||
}
|
}
|
||||||
@@ -701,10 +701,11 @@ BShelf::Save()
|
|||||||
if (fEntry != NULL) {
|
if (fEntry != NULL) {
|
||||||
BFile *file = new BFile(fEntry, B_READ_WRITE | B_ERASE_FILE);
|
BFile *file = new BFile(fEntry, B_READ_WRITE | B_ERASE_FILE);
|
||||||
status = file->InitCheck();
|
status = file->InitCheck();
|
||||||
if (status < B_OK) {
|
if (status != B_OK) {
|
||||||
delete file;
|
delete file;
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
delete fStream;
|
||||||
fStream = file;
|
fStream = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -901,7 +902,7 @@ BShelf::SetSaveLocation(BDataIO *data_io)
|
|||||||
{
|
{
|
||||||
fDirty = true;
|
fDirty = true;
|
||||||
|
|
||||||
if (fEntry) {
|
if (fEntry != NULL) {
|
||||||
delete fEntry;
|
delete fEntry;
|
||||||
fEntry = NULL;
|
fEntry = NULL;
|
||||||
}
|
}
|
||||||
@@ -1145,7 +1146,7 @@ BShelf::_InitData(BEntry *entry, BDataIO *stream, BView *view,
|
|||||||
fAllowZombies = true;
|
fAllowZombies = true;
|
||||||
fTypeEnforced = false;
|
fTypeEnforced = false;
|
||||||
|
|
||||||
if (entry)
|
if (fEntry != NULL)
|
||||||
fStream = new BFile(entry, B_READ_ONLY);
|
fStream = new BFile(entry, B_READ_ONLY);
|
||||||
else
|
else
|
||||||
fStream = stream;
|
fStream = stream;
|
||||||
@@ -1155,7 +1156,7 @@ BShelf::_InitData(BEntry *entry, BDataIO *stream, BView *view,
|
|||||||
fContainerView->AddFilter(fFilter);
|
fContainerView->AddFilter(fFilter);
|
||||||
fContainerView->_SetShelf(this);
|
fContainerView->_SetShelf(this);
|
||||||
|
|
||||||
if (fStream) {
|
if (fStream != NULL) {
|
||||||
BMessage archive;
|
BMessage archive;
|
||||||
|
|
||||||
if (archive.Unflatten(fStream) == B_OK) {
|
if (archive.Unflatten(fStream) == B_OK) {
|
||||||
@@ -1195,10 +1196,10 @@ BShelf::_DeleteReplicant(replicant_data* item)
|
|||||||
if (view == NULL)
|
if (view == NULL)
|
||||||
view = item->zombie_view;
|
view = item->zombie_view;
|
||||||
|
|
||||||
if (view)
|
if (view != NULL)
|
||||||
view->RemoveSelf();
|
view->RemoveSelf();
|
||||||
|
|
||||||
if (item->dragger)
|
if (item->dragger != NULL)
|
||||||
item->dragger->RemoveSelf();
|
item->dragger->RemoveSelf();
|
||||||
|
|
||||||
int32 index = replicant_data::IndexOf(&fReplicants, item->message);
|
int32 index = replicant_data::IndexOf(&fReplicants, item->message);
|
||||||
@@ -1291,27 +1292,25 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
|
|||||||
|
|
||||||
BView *view = NULL;
|
BView *view = NULL;
|
||||||
|
|
||||||
if (archivable) {
|
if (archivable != NULL) {
|
||||||
view = dynamic_cast<BView*>(archivable);
|
view = dynamic_cast<BView*>(archivable);
|
||||||
|
|
||||||
if (!view) {
|
if (view == NULL)
|
||||||
return send_reply(data, B_ERROR, uniqueID);
|
return send_reply(data, B_ERROR, uniqueID);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BDragger* dragger = NULL;
|
BDragger* dragger = NULL;
|
||||||
BView* replicant = NULL;
|
BView* replicant = NULL;
|
||||||
BDragger::relation relation = BDragger::TARGET_UNKNOWN;
|
BDragger::relation relation = BDragger::TARGET_UNKNOWN;
|
||||||
_BZombieReplicantView_* zombie = NULL;
|
_BZombieReplicantView_* zombie = NULL;
|
||||||
if (view) {
|
if (view != NULL) {
|
||||||
const BPoint point = location ? *location : view->Frame().LeftTop();
|
const BPoint point = location ? *location : view->Frame().LeftTop();
|
||||||
replicant = _GetReplicant(data, view, point, dragger, relation);
|
replicant = _GetReplicant(data, view, point, dragger, relation);
|
||||||
if (replicant == NULL)
|
if (replicant == NULL)
|
||||||
return send_reply(data, B_ERROR, uniqueID);
|
return send_reply(data, B_ERROR, uniqueID);
|
||||||
} else if (fDisplayZombies && fAllowZombies)
|
} else if (fDisplayZombies && fAllowZombies) {
|
||||||
zombie = _CreateZombie(data, dragger);
|
zombie = _CreateZombie(data, dragger);
|
||||||
|
} else if (!fAllowZombies) {
|
||||||
else if (!fAllowZombies) {
|
|
||||||
// There was no view, and we're not allowed to have any zombies
|
// There was no view, and we're not allowed to have any zombies
|
||||||
// in the house
|
// in the house
|
||||||
return send_reply(data, B_ERROR, uniqueID);
|
return send_reply(data, B_ERROR, uniqueID);
|
||||||
@@ -1334,7 +1333,7 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!zombie) {
|
if (zombie == NULL) {
|
||||||
data->RemoveName("_drop_point_");
|
data->RemoveName("_drop_point_");
|
||||||
data->RemoveName("_drop_offset_");
|
data->RemoveName("_drop_offset_");
|
||||||
}
|
}
|
||||||
@@ -1353,7 +1352,7 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
|
|||||||
|
|
||||||
BView *
|
BView *
|
||||||
BShelf::_GetReplicant(BMessage *data, BView *view, const BPoint &point,
|
BShelf::_GetReplicant(BMessage *data, BView *view, const BPoint &point,
|
||||||
BDragger *&dragger, BDragger::relation &relation)
|
BDragger *&dragger, BDragger::relation &relation)
|
||||||
{
|
{
|
||||||
// TODO: test me -- there seems to be lots of bugs parked here!
|
// TODO: test me -- there seems to be lots of bugs parked here!
|
||||||
BView *replicant = NULL;
|
BView *replicant = NULL;
|
||||||
@@ -1401,7 +1400,7 @@ BShelf::_GetReplicant(BMessage *data, BView *view, const BPoint &point,
|
|||||||
/* static */
|
/* static */
|
||||||
void
|
void
|
||||||
BShelf::_GetReplicantData(BMessage *data, BView *view, BView *&replicant,
|
BShelf::_GetReplicantData(BMessage *data, BView *view, BView *&replicant,
|
||||||
BDragger *&dragger, BDragger::relation &relation)
|
BDragger *&dragger, BDragger::relation &relation)
|
||||||
{
|
{
|
||||||
// Check if we have a dragger archived as "__widget" inside the message
|
// Check if we have a dragger archived as "__widget" inside the message
|
||||||
BMessage widget;
|
BMessage widget;
|
||||||
|
|||||||
Reference in New Issue
Block a user