Skip to content

Commit

Permalink
Fixed crash if bind_address is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
mojyack committed Oct 18, 2024
1 parent ab1a8f8 commit f23b2d7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ static conn_registry_t *acquire_registry(conn_mode_entry_t *entry, udp_socket_co
conn_registry_t *registry = entry->registry;
if (!registry) {
if (!entry->registry_init_func)
return NULL;
return (void*)-1;

JLOG_DEBUG("Creating connections registry");

registry = calloc(1, sizeof(conn_registry_t));
if (!registry) {
JLOG_FATAL("Memory allocation failed for connections registry");
return NULL;
return (void*)-1;
}

registry->agents = malloc(INITIAL_REGISTRY_SIZE * sizeof(juice_agent_t *));
if (!registry->agents) {
JLOG_FATAL("Memory allocation failed for connections array");
free(registry);
return NULL;
return (void*)-1;
}

registry->agents_size = INITIAL_REGISTRY_SIZE;
Expand All @@ -84,10 +84,11 @@ static conn_registry_t *acquire_registry(conn_mode_entry_t *entry, udp_socket_co
mutex_lock(&registry->mutex);

if (entry->registry_init_func(registry, config)) {
JLOG_FATAL("Registry initialization failed");
mutex_unlock(&registry->mutex);
free(registry->agents);
free(registry);
return NULL;
return (void*)-1;
}

entry->registry = registry;
Expand Down Expand Up @@ -132,6 +133,9 @@ int conn_create(juice_agent_t *agent, udp_socket_config_t *config) {
mutex_lock(&entry->mutex);
conn_registry_t *registry = acquire_registry(entry, config); // locks the registry if created
mutex_unlock(&entry->mutex);
if(registry == (void*)-1) {
return -1;
}

JLOG_DEBUG("Creating connection");
if (registry) {
Expand Down

0 comments on commit f23b2d7

Please sign in to comment.