struct ll *lldel(struct ll *curll, void *object,
int (*objectcmp) (const void *object1, const void *object2))
{
- struct ll *cur;
+ struct ll *cur = NULL;
+ struct ll *old = NULL;
assert(objectcmp != NULL);
if (cur == NULL) {
return NULL;
} else if (!(*objectcmp)(cur->object, object)) {
- return cur->next;
+ old = cur;
+ cur = cur->next;
+ free(old);
+ return cur;
}
while (cur->next != NULL) {
if (!(*objectcmp)(cur->next->object, object)) {
+ old = cur->next;
cur->next = cur->next->next;
+ free(old);
break;
}
}
{
struct ll *cur;
+ assert(objectcmp != NULL);
+
cur = curll;
while (cur != NULL && (*objectcmp)(cur->object, object)) {
cur = cur->next;