Fix for segmentation fault from freed memory access in jtag_unregister_event_callback()

This commit is contained in:
Paul Richards 2010-12-08 15:48:55 +09:00 committed by Øyvind Harboe
parent 4bd2b30d5b
commit b8c42b985d
1 changed files with 9 additions and 13 deletions

View File

@ -296,28 +296,24 @@ int jtag_register_event_callback(jtag_event_handler_t callback, void *priv)
int jtag_unregister_event_callback(jtag_event_handler_t callback, void *priv) int jtag_unregister_event_callback(jtag_event_handler_t callback, void *priv)
{ {
struct jtag_event_callback **callbacks_p; struct jtag_event_callback **p = &jtag_event_callbacks, *temp;
struct jtag_event_callback **next;
if (callback == NULL) if (callback == NULL)
{ {
return ERROR_INVALID_ARGUMENTS; return ERROR_INVALID_ARGUMENTS;
} }
for (callbacks_p = &jtag_event_callbacks; while (*p)
*callbacks_p != NULL;
callbacks_p = next)
{ {
next = &((*callbacks_p)->next); if (((*p)->priv != priv) || ((*p)->callback != callback))
if ((*callbacks_p)->priv != priv)
continue;
if ((*callbacks_p)->callback == callback)
{ {
free(*callbacks_p); p = &(*p)->next;
*callbacks_p = *next; continue;
} }
temp = *p;
*p = (*p)->next;
free(temp);
} }
return ERROR_OK; return ERROR_OK;