I have a function that goes like this:
Code:
List ListRemove(List list, Contents * item)
{
Node *searchNode, *prevNode;
/* look at each node until found item */
for(searchNode = ListFront(list), prevNode = NULL;
searchNode != NULL && NodeContents(searchNode) != item;
prevNode = searchNode, searchNode = NodeNext(searchNode));
/* item not found */
if(searchNode == NULL) return list;
/* item is first node */
if(prevNode == NULL) list = NodeNext(list);
/* item is another node */
else prevNode->next = NodeNext(searchNode);
free(searchNode);
return list;
}
is this OK?
If I run the program with bcheck, and enter n items into the list, then quit, I get 2*n memory leaks. If I remove the items in the list, I get n memory leaks. The bcheck .err file seems to point at strdup as the culprit, so I thought that may be the problem.