Skip to content

Commit 85f88f4

Browse files
Merge pull request #278 from mojyack/master
Fixed race condition potentially resulting in referencing freed registry
2 parents 201b2c9 + f2b919f commit 85f88f4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/conn.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ int conn_create(juice_agent_t *agent, udp_socket_config_t *config) {
136136
return -1;
137137
}
138138
conn_registry_t *registry = entry->registry;
139-
mutex_unlock(&entry->mutex);
140139

141140
JLOG_DEBUG("Creating connection");
142141
if (registry) {
@@ -154,6 +153,7 @@ int conn_create(juice_agent_t *agent, udp_socket_config_t *config) {
154153
if (!new_agents) {
155154
JLOG_FATAL("Memory reallocation failed for connections array");
156155
mutex_unlock(&registry->mutex);
156+
mutex_unlock(&entry->mutex);
157157
return -1;
158158
}
159159

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

165165
if (get_mode_entry(agent)->init_func(agent, registry, config)) {
166166
release_registry(entry); // unlocks the registry
167+
mutex_unlock(&entry->mutex);
167168
return -1;
168169
}
169170

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

176177
} else {
177178
if (get_mode_entry(agent)->init_func(agent, NULL, config)) {
178-
mutex_unlock(&registry->mutex);
179+
mutex_unlock(&entry->mutex);
179180
return -1;
180181
}
181182

182183
agent->conn_index = -1;
183184
}
184185

186+
mutex_unlock(&entry->mutex);
185187
conn_interrupt(agent);
186188
return 0;
187189
}

0 commit comments

Comments
 (0)