diff options
author | Paul Richards <paulr227@gmail.com> | 2010-12-08 15:48:55 +0900 |
---|---|---|
committer | Øyvind Harboe <oyvind.harboe@zylin.com> | 2010-12-10 08:03:01 +0100 |
commit | b8c42b985d725ed92b97f8c6cb871a90425b9fa8 (patch) | |
tree | 7548fba5ab7bb53bb2078bb5a95afea3ba9a9e84 /src | |
parent | 4bd2b30d5bae59b751f8eb30815cf330faae2a6f (diff) | |
download | openocd_libswd-b8c42b985d725ed92b97f8c6cb871a90425b9fa8.tar.gz openocd_libswd-b8c42b985d725ed92b97f8c6cb871a90425b9fa8.tar.bz2 openocd_libswd-b8c42b985d725ed92b97f8c6cb871a90425b9fa8.tar.xz openocd_libswd-b8c42b985d725ed92b97f8c6cb871a90425b9fa8.zip |
Fix for segmentation fault from freed memory access in jtag_unregister_event_callback()
Diffstat (limited to 'src')
-rw-r--r-- | src/jtag/core.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/jtag/core.c b/src/jtag/core.c index b8953094..dfedc172 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -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) { - struct jtag_event_callback **callbacks_p; - struct jtag_event_callback **next; + struct jtag_event_callback **p = &jtag_event_callbacks, *temp; if (callback == NULL) { return ERROR_INVALID_ARGUMENTS; } - for (callbacks_p = &jtag_event_callbacks; - *callbacks_p != NULL; - callbacks_p = next) + while (*p) { - next = &((*callbacks_p)->next); - - if ((*callbacks_p)->priv != priv) - continue; - - if ((*callbacks_p)->callback == callback) + if (((*p)->priv != priv) || ((*p)->callback != callback)) { - free(*callbacks_p); - *callbacks_p = *next; + p = &(*p)->next; + continue; } + + temp = *p; + *p = (*p)->next; + free(temp); } return ERROR_OK; |