init_thread_stop maintains a linked lists of handlers that it should
call when a thread finishes. The linked list handling wasn't quite right
resulting in corrupted data.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/10863)
static void init_thread_stop(void *arg, THREAD_EVENT_HANDLER **hands)
{
- THREAD_EVENT_HANDLER *curr, *prev = NULL;
+ THREAD_EVENT_HANDLER *curr, *prev = NULL, *tmp;
/* Can't do much about this */
if (hands == NULL)
curr = *hands;
while (curr != NULL) {
if (arg != NULL && curr->arg != arg) {
+ prev = curr;
curr = curr->next;
continue;
}
curr->handfn(curr->arg);
- prev = curr;
+ if (prev == NULL)
+ *hands = curr->next;
+ else
+ prev->next = curr->next;
+
+ tmp = curr;
curr = curr->next;
- if (prev == *hands)
- *hands = curr;
- OPENSSL_free(prev);
+
+ OPENSSL_free(tmp);
}
}