Skip to content

Commit

Permalink
Fixed race condition potentially resulting in referencing freed registry
Browse files Browse the repository at this point in the history
  • Loading branch information
mojyack committed Oct 24, 2024
1 parent 201b2c9 commit f2b919f
Showing 1 changed file with 4 additions and 2 deletions.
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

0 comments on commit f2b919f

Please sign in to comment.