- fixed bug in cleanCallbackList

This commit is contained in:
zolliker
2009-03-17 11:55:14 +00:00
parent 133129c8c9
commit 08599649d4

View File

@ -135,37 +135,28 @@ static void markUserdata4Kill(pICallBack self, void *pData)
/*-------------------------------------------------------------------------*/
static void cleanCallbackList(pICallBack self)
{
pCallBackItem toKill, current;
pCallBackItem toKill, current, previous;
/*
* killing at the head
*/
while (self->head != NULL && self->head->killFlag == 0) {
toKill = self->head;
self->head = toKill->next;
if (toKill->pKill != NULL) {
toKill->pKill(toKill->pUserData);
}
free(toKill);
}
if (self->head == NULL) {
return;
}
/*
* killing in the middle and the end
*/
previous = NULL;
current = self->head;
while (current->next != NULL) {
if (current->next->killFlag == 1) {
toKill = current->next;
current->next = toKill->next;
while (current != NULL) {
if (current->killFlag == 1) {
toKill = current;
current = current->next;
/* update link from previous item or from head */
if (previous == NULL) {
self->head = current;
} else {
previous->next = current;
}
if (toKill->pKill != NULL) {
toKill->pKill(toKill->pUserData);
}
free(toKill);
} else {
previous = current;
current = current->next;
}
}