Fix memory leaks introduced in previous commits.

This commit is contained in:
Rene Gollent
2013-05-09 17:31:42 -04:00
parent 2b67ff2420
commit 3313492032
@@ -37,8 +37,6 @@ public:
fSourceFile(sourceFile), fSourceFile(sourceFile),
fFunction(function) fFunction(function)
{ {
if (fParent != NULL)
fParent->AcquireReference();
if (fSourceFile != NULL) if (fSourceFile != NULL)
fSourceFile->AcquireReference(); fSourceFile->AcquireReference();
if (fFunction != NULL) if (fFunction != NULL)
@@ -50,14 +48,11 @@ public:
for (int32 i = 0; i < fChildPathComponents.CountItems(); i++) for (int32 i = 0; i < fChildPathComponents.CountItems(); i++)
fChildPathComponents.ItemAt(i)->ReleaseReference(); fChildPathComponents.ItemAt(i)->ReleaseReference();
if (fParent != NULL)
fParent->ReleaseReference();
if (fSourceFile != NULL) if (fSourceFile != NULL)
fSourceFile->ReleaseReference(); fSourceFile->ReleaseReference();
if (fFunction != NULL) if (fFunction != NULL)
fFunction->AcquireReference(); fFunction->ReleaseReference();
} }
const BString& ComponentName() const const BString& ComponentName() const
@@ -223,8 +218,8 @@ public:
SourcePathComponentNode* sourcelessNode = new(std::nothrow) SourcePathComponentNode* sourcelessNode = new(std::nothrow)
SourcePathComponentNode(NULL, "<no source file>", NULL, NULL); SourcePathComponentNode(NULL, "<no source file>", NULL, NULL);
ObjectDeleter<SourcePathComponentNode> sourceNodeDeleter( BReference<SourcePathComponentNode> sourceNodeRef(
sourcelessNode); sourcelessNode, true);
for (int32 i = 0; i < functionCount; i++) { for (int32 i = 0; i < functionCount; i++) {
@@ -236,7 +231,7 @@ public:
if (fChildPathComponents.BinaryInsert(sourcelessNode, if (fChildPathComponents.BinaryInsert(sourcelessNode,
&SourcePathComponentNode::CompareComponents)) { &SourcePathComponentNode::CompareComponents)) {
fSourcelessNode = sourcelessNode; fSourcelessNode = sourcelessNode;
sourceNodeDeleter.Detach(); sourceNodeRef.Detach();
} }
} }
@@ -404,7 +399,8 @@ private:
pathComponent, NULL, NULL); pathComponent, NULL, NULL);
if (currentNode == NULL) if (currentNode == NULL)
return false; return false;
ObjectDeleter<SourcePathComponentNode> nodeDeleter(currentNode); BReference<SourcePathComponentNode> nodeReference(currentNode,
true);
if (parent != NULL) { if (parent != NULL) {
if (!parent->AddChild(currentNode)) if (!parent->AddChild(currentNode))
return false; return false;
@@ -413,8 +409,9 @@ private:
&SourcePathComponentNode::CompareComponents)) { &SourcePathComponentNode::CompareComponents)) {
return false; return false;
} }
nodeReference.Detach();
} }
nodeDeleter.Detach();
} }
if (pathSeparatorIndex == -1) if (pathSeparatorIndex == -1)
@@ -433,12 +430,10 @@ private:
if (functionNode == NULL) if (functionNode == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
ObjectDeleter<SourcePathComponentNode> nodeDeleter(functionNode); BReference<SourcePathComponentNode> nodeReference(functionNode, true);
if (!parent->AddChild(functionNode)) if (!parent->AddChild(functionNode))
return false; return false;
nodeDeleter.Detach();
return true; return true;
} }