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:
@@ -13,7 +13,7 @@
|
|||||||
// constructor
|
// constructor
|
||||||
Entry::Entry(const char *name, Node *node, Directory *parent)
|
Entry::Entry(const char *name, Node *node, Directory *parent)
|
||||||
: fParent(parent),
|
: fParent(parent),
|
||||||
fNode(node),
|
fNode(NULL),
|
||||||
fName(name),
|
fName(name),
|
||||||
fReferrerLink(),
|
fReferrerLink(),
|
||||||
fIterators()
|
fIterators()
|
||||||
@@ -40,17 +40,18 @@ Entry::InitCheck() const
|
|||||||
status_t
|
status_t
|
||||||
Entry::Link(Node *node)
|
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) {
|
if (error == B_OK) {
|
||||||
// We first link to the new node and then unlink the old one. So, no
|
fNode = node;
|
||||||
// harm is done, if both are the same.
|
if (oldNode)
|
||||||
Node *oldNode = fNode;
|
oldNode->Unlink(this);
|
||||||
error = node->Link(this);
|
|
||||||
if (error == B_OK) {
|
|
||||||
fNode = node;
|
|
||||||
if (oldNode)
|
|
||||||
oldNode->Unlink(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -101,4 +102,3 @@ Entry::GetAllocationInfo(AllocationInfo &info)
|
|||||||
info.AddStringAllocation(fName.GetLength());
|
info.AddStringAllocation(fName.GetLength());
|
||||||
fNode->GetAllocationInfo(info);
|
fNode->GetAllocationInfo(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user