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

Fixed race condition potentially resulting in referencing freed registry #278

Merged
merged 1 commit into from
Oct 24, 2024
Merged
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
6 changes: 4 additions & 2 deletions src/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ int conn_create(juice_agent_t *agent, udp_socket_config_t *config) {
return -1;
}
conn_registry_t *registry = entry->registry;
mutex_unlock(&entry->mutex);

JLOG_DEBUG("Creating connection");
if (registry) {
Expand All @@ -154,6 +153,7 @@ int conn_create(juice_agent_t *agent, udp_socket_config_t *config) {
if (!new_agents) {
JLOG_FATAL("Memory reallocation failed for connections array");
mutex_unlock(&registry->mutex);
mutex_unlock(&entry->mutex);
return -1;
}

Expand All @@ -164,6 +164,7 @@ int conn_create(juice_agent_t *agent, udp_socket_config_t *config) {

if (get_mode_entry(agent)->init_func(agent, registry, config)) {
release_registry(entry); // unlocks the registry
mutex_unlock(&entry->mutex);
return -1;
}

Expand All @@ -175,13 +176,14 @@ int conn_create(juice_agent_t *agent, udp_socket_config_t *config) {

} else {
if (get_mode_entry(agent)->init_func(agent, NULL, config)) {
mutex_unlock(&registry->mutex);
mutex_unlock(&entry->mutex);
return -1;
}

agent->conn_index = -1;
}

mutex_unlock(&entry->mutex);
conn_interrupt(agent);
return 0;
}
Expand Down
Loading