Skip to content
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

udp: fix helpers mutex locking #1104

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions src/udp/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,20 @@ static void udp_read(struct udp_sock *us, re_sock_t fd)
/* call helpers */
mtx_lock(us->lock);
le = us->helpers.head;
mtx_unlock(us->lock);
while (le) {
struct udp_helper *uh = le->data;
bool hdld;

mtx_lock(us->lock);
le = le->next;
mtx_unlock(us->lock);

hdld = uh->recvh(&src, mb, uh->arg);
if (hdld)
if (hdld) {
mtx_unlock(us->lock);
goto out;
}
}

mtx_unlock(us->lock);
us->rh(&src, mb, us->arg);

out:
Expand Down Expand Up @@ -936,26 +936,24 @@ void udp_recv_helper(struct udp_sock *us, const struct sa *src,
struct udp_helper *udp_helper_find(const struct udp_sock *us, int layer)
{
struct le *le;
struct udp_helper *uh = NULL;

if (!us)
return NULL;

mtx_lock(us->lock);
le = us->helpers.head;
mtx_unlock(us->lock);
while (le) {

struct udp_helper *uh = le->data;

mtx_lock(us->lock);
uh = le->data;
le = le->next;
mtx_unlock(us->lock);

if (layer == uh->layer)
return uh;
break;
}

return NULL;
mtx_unlock(us->lock);

return le ? uh : NULL;
}


Expand Down Expand Up @@ -997,24 +995,24 @@ void udp_recv_packet(struct udp_sock *us, const struct sa *src,

mtx_lock(us->lock);
le = us->helpers.head;
mtx_unlock(us->lock);
while (le) {
struct udp_helper *uh = le->data;
bool hdld;

mtx_lock(us->lock);
le = le->next;
mtx_unlock(us->lock);

if (src != &hsrc) {
sa_cpy(&hsrc, src);
src = &hsrc;
}

hdld = uh->recvh(&hsrc, mb, uh->arg);
if (hdld)
if (hdld) {
mtx_unlock(us->lock);
return;
}
}

mtx_unlock(us->lock);
us->rh(src, mb, us->arg);
}
Loading