ramfs: Correct usage of Nodes in Entry.
* We do not want to set fNode in the constructor but let the invocation of Link() take care of doing so instead. * Link/Unlink manipulate linked-lists. Thus it is dangerous to use them in tandem on the same Node object. Add a check for this. * Minor cleanup.
This commit is contained in:
parent
8426404f97
commit
6a8bb0562e
@ -13,7 +13,7 @@
|
||||
// constructor
|
||||
Entry::Entry(const char *name, Node *node, Directory *parent)
|
||||
: fParent(parent),
|
||||
fNode(node),
|
||||
fNode(NULL),
|
||||
fName(name),
|
||||
fReferrerLink(),
|
||||
fIterators()
|
||||
@ -40,17 +40,18 @@ Entry::InitCheck() const
|
||||
status_t
|
||||
Entry::Link(Node *node)
|
||||
{
|
||||
status_t error = (node ? B_OK : B_BAD_VALUE);
|
||||
if (node == NULL)
|
||||
return B_BAD_VALUE;
|
||||
if (node == fNode)
|
||||
return B_OK;
|
||||
|
||||
// We first link to the new node and then unlink the old one.
|
||||
Node *oldNode = fNode;
|
||||
status_t error = node->Link(this);
|
||||
if (error == B_OK) {
|
||||
// We first link to the new node and then unlink the old one. So, no
|
||||
// harm is done, if both are the same.
|
||||
Node *oldNode = fNode;
|
||||
error = node->Link(this);
|
||||
if (error == B_OK) {
|
||||
fNode = node;
|
||||
if (oldNode)
|
||||
oldNode->Unlink(this);
|
||||
}
|
||||
fNode = node;
|
||||
if (oldNode)
|
||||
oldNode->Unlink(this);
|
||||
}
|
||||
return error;
|
||||
}
|
||||
@ -101,4 +102,3 @@ Entry::GetAllocationInfo(AllocationInfo &info)
|
||||
info.AddStringAllocation(fName.GetLength());
|
||||
fNode->GetAllocationInfo(info);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user