sreimers, Thank you for your reply.
- The first approach directly modifies the le pointer during the list traversal. If an exception occurs or the list structure is modified in list_unlink or mem_deref, it may cause the traversal to be interrupted or access already freed memory.
- The second approach uses the LIST_FOREACH_SAFE macro, which safely traverses the list using two pointers, le and n. Even if the list structure is modified in list_unlink or mem_deref, it will not affect the safety of the traversal.
I tried to use it, but it didn't work.
#if 0
LIST_FOREACH_SAFE(&turndp()->rm_map, le, n)
{
struct udp_socks *uks = list_ledata(le);
if (thrd_id == uks->thrd_id) {
udp_thread_detach(uks->rel_us);
udp_thread_detach(uks->rsv_us);
list_unlink(&uks->le);
mem_deref(uks);
}
}
#endif
#if 1
le = list_head(&turndp()->rm_map);
while (le)
{
struct udp_socks *uks = list_ledata(le);
if (thrd_id == uks->thrd_id) {
le = le->next;
udp_thread_detach(uks->rel_us);
udp_thread_detach(uks->rsv_us);
list_unlink(&uks->le);
mem_deref(uks);
}
}
#endif
sreimers, Thank you for your reply.
I tried to use it, but it didn't work.