- fixed bug in cleanCallbackList
This commit is contained in:
39
callback.c
39
callback.c
@ -135,37 +135,28 @@ static void markUserdata4Kill(pICallBack self, void *pData)
|
|||||||
/*-------------------------------------------------------------------------*/
|
/*-------------------------------------------------------------------------*/
|
||||||
static void cleanCallbackList(pICallBack self)
|
static void cleanCallbackList(pICallBack self)
|
||||||
{
|
{
|
||||||
pCallBackItem toKill, current;
|
pCallBackItem toKill, current, previous;
|
||||||
|
|
||||||
/*
|
previous = NULL;
|
||||||
* 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
|
|
||||||
*/
|
|
||||||
current = self->head;
|
current = self->head;
|
||||||
while (current->next != NULL) {
|
while (current != NULL) {
|
||||||
if (current->next->killFlag == 1) {
|
if (current->killFlag == 1) {
|
||||||
toKill = current->next;
|
toKill = current;
|
||||||
current->next = toKill->next;
|
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) {
|
if (toKill->pKill != NULL) {
|
||||||
toKill->pKill(toKill->pUserData);
|
toKill->pKill(toKill->pUserData);
|
||||||
}
|
}
|
||||||
free(toKill);
|
free(toKill);
|
||||||
} else {
|
} else {
|
||||||
|
previous = current;
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user