Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list: about add macro LIST_FOREACH_SAFE #1199

Closed
jobo-zt opened this issue Oct 18, 2024 · 1 comment
Closed

list: about add macro LIST_FOREACH_SAFE #1199

jobo-zt opened this issue Oct 18, 2024 · 1 comment

Comments

@jobo-zt
Copy link
Contributor

jobo-zt commented Oct 18, 2024

sreimers, Thank you for your reply.

  1. 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.
  2. 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
@jobo-zt
Copy link
Contributor Author

jobo-zt commented Oct 18, 2024

#1197

@baresip baresip locked and limited conversation to collaborators Oct 18, 2024
@sreimers sreimers converted this issue into discussion #1200 Oct 18, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant