Commit 8b6568da authored by Youness Alaoui's avatar Youness Alaoui

Clean discovery_add_local_host_candidate to avoid memleaks if an error occurs

parent 02fd911e
...@@ -289,57 +289,52 @@ NiceCandidate *discovery_add_local_host_candidate ( ...@@ -289,57 +289,52 @@ NiceCandidate *discovery_add_local_host_candidate (
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_HOST); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_HOST);
if (candidate) { if (candidate) {
NiceUDPSocket *udp_socket = g_slice_new0 (NiceUDPSocket); candidate->stream_id = stream_id;
if (udp_socket) { candidate->component_id = component_id;
candidate->stream_id = stream_id; candidate->addr = *address;
candidate->component_id = component_id; candidate->base_addr = *address;
candidate->addr = *address; if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
candidate->base_addr = *address; candidate->priority = nice_candidate_jingle_priority (candidate) * 1000;
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) { } else if (agent->compatibility == NICE_COMPATIBILITY_MSN) {
candidate->priority = nice_candidate_jingle_priority (candidate) * 1000; candidate->priority = nice_candidate_msn_priority (candidate) * 1000;
} else if (agent->compatibility == NICE_COMPATIBILITY_MSN) { } else {
candidate->priority = nice_candidate_msn_priority (candidate) * 1000; candidate->priority = nice_candidate_ice_priority (candidate);
} else { }
candidate->priority = nice_candidate_ice_priority (candidate);
}
priv_generate_candidate_credentials (agent, candidate); priv_generate_candidate_credentials (agent, candidate);
priv_assign_foundation (agent, candidate); priv_assign_foundation (agent, candidate);
/* note: candidate username and password are left NULL as stream /* note: candidate username and password are left NULL as stream
level ufrag/password are used */ level ufrag/password are used */
if (nice_udp_socket_factory_make (&agent->udp_socket_factory, udp_socket = nice_socket_new (agent->udp_socket_factory, address);
udp_socket, address)) { if (udp_socket) {
gboolean result; gboolean result;
priv_attach_stream_component_socket (agent, stream, component, priv_attach_stream_component_socket (agent, stream, component, udp_socket);
udp_socket);
candidate->sockptr = udp_socket;
candidate->sockptr = udp_socket; candidate->addr = udp_socket->addr;
candidate->addr = udp_socket->addr; candidate->base_addr = udp_socket->addr;
candidate->base_addr = udp_socket->addr;
result = priv_add_local_candidate_pruned (component, candidate);
result = priv_add_local_candidate_pruned (component, candidate);
if (result == TRUE) {
if (result == TRUE) { GSList *modified_list = g_slist_append (component->sockets, udp_socket);
GSList *modified_list = g_slist_append (component->sockets, udp_socket); if (modified_list) {
if (modified_list) { /* success: store a pointer to the sockaddr */
/* success: store a pointer to the sockaddr */ component->sockets = modified_list;
component->sockets = modified_list; agent_signal_new_candidate (agent, candidate);
agent_signal_new_candidate (agent, candidate); } else { /* error: list memory allocation */
} candidate = NULL; /* note: candidate already owned by component */
else { /* error: list memory allocation */ }
candidate = NULL; /* note: candidate already owned by component */ } else {
} /* error: memory allocation, or duplicate candidates */
} errors = TRUE;
else /* error: memory allocation, or duplicate candidatet */
errors = TRUE;
} }
else /* error: socket factory make */ } else {
errors = TRUE; /* error: socket new */
}
else /* error: udp socket memory allocation */
errors = TRUE; errors = TRUE;
}
} }
/* clean up after errors */ /* clean up after errors */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment