summaryrefslogtreecommitdiff
path: root/lib/frr_pthread.c
diff options
context:
space:
mode:
authorRuss White <russ@riw.us>2019-09-17 07:27:12 -0400
committerGitHub <noreply@github.com>2019-09-17 07:27:12 -0400
commit321b1efab2d66ff8d7a868ca6ef6b0bd879f8f32 (patch)
tree939d6898e9ea4b020f30ba1a7ef6d673868980b6 /lib/frr_pthread.c
parentfe8d933c2c778647b3fbb75340ea4f752c77137d (diff)
parentdf54f0536ec0fa84034bfa5e5205d612dc1321df (diff)
Merge pull request #4810 from qlyoung/fix-pthread-bad-pointer
Fix potential frr_pthread.c stale pointer
Diffstat (limited to 'lib/frr_pthread.c')
-rw-r--r--lib/frr_pthread.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c
index 21dfc9256f..97550eae53 100644
--- a/lib/frr_pthread.c
+++ b/lib/frr_pthread.c
@@ -51,12 +51,13 @@ void frr_pthread_init(void)
{
frr_with_mutex(&frr_pthread_list_mtx) {
frr_pthread_list = list_new();
- frr_pthread_list->del = (void (*)(void *))&frr_pthread_destroy;
}
}
void frr_pthread_finish(void)
{
+ frr_pthread_stop_all();
+
frr_with_mutex(&frr_pthread_list_mtx) {
list_delete(&frr_pthread_list);
}
@@ -99,8 +100,11 @@ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr,
void frr_pthread_destroy(struct frr_pthread *fpt)
{
- thread_master_free(fpt->master);
+ frr_with_mutex(&frr_pthread_list_mtx) {
+ listnode_delete(frr_pthread_list, fpt);
+ }
+ thread_master_free(fpt->master);
pthread_mutex_destroy(&fpt->mtx);
pthread_mutex_destroy(fpt->running_cond_mtx);
pthread_cond_destroy(fpt->running_cond);
@@ -183,8 +187,11 @@ void frr_pthread_stop_all(void)
frr_with_mutex(&frr_pthread_list_mtx) {
struct listnode *n;
struct frr_pthread *fpt;
- for (ALL_LIST_ELEMENTS_RO(frr_pthread_list, n, fpt))
- frr_pthread_stop(fpt, NULL);
+ for (ALL_LIST_ELEMENTS_RO(frr_pthread_list, n, fpt)) {
+ if (atomic_load_explicit(&fpt->running,
+ memory_order_relaxed))
+ frr_pthread_stop(fpt, NULL);
+ }
}
}