🐛 Stop linked list delete from storing a disposed node
Delete continued the loop with a dangling previous-node pointer after disposing the matched entry. It now returns after the first match, which is the behavior all callers rely on.
This commit is contained in:
+8
-10
@@ -95,7 +95,7 @@ end;
|
||||
|
||||
procedure TLinkedList.Delete(AData: Pointer);
|
||||
var
|
||||
currentItem, lastItem, nextItem: PLinkedItem;
|
||||
currentItem, lastItem: PLinkedItem;
|
||||
begin
|
||||
lastItem := nil;
|
||||
currentItem := FFirst;
|
||||
@@ -107,17 +107,16 @@ begin
|
||||
if FLast = currentItem then FLast := lastItem;
|
||||
if lastItem <> nil then lastItem^.Next := currentItem^.Next;
|
||||
Dispose(currentItem);
|
||||
nextItem := nil;
|
||||
end else
|
||||
nextItem := currentItem^.Next;
|
||||
Exit;
|
||||
end;
|
||||
lastItem := currentItem;
|
||||
currentItem := nextItem;
|
||||
currentItem := currentItem^.Next;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TLinkedList.Delete(AID: Integer);
|
||||
var
|
||||
currentItem, lastItem, nextItem: PLinkedItem;
|
||||
currentItem, lastItem: PLinkedItem;
|
||||
begin
|
||||
lastItem := nil;
|
||||
currentItem := FFirst;
|
||||
@@ -129,11 +128,10 @@ begin
|
||||
if FLast = currentItem then FLast := lastItem;
|
||||
if lastItem <> nil then lastItem^.Next := currentItem^.Next;
|
||||
Dispose(currentItem);
|
||||
nextItem := nil;
|
||||
end else
|
||||
nextItem := currentItem^.Next;
|
||||
Exit;
|
||||
end;
|
||||
lastItem := currentItem;
|
||||
currentItem := nextItem;
|
||||
currentItem := currentItem^.Next;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user