Browse Source

Add missing close socket when ioa_socket call fails (#1694)

Fixes [#1071](https://github.com/coturn/coturn/issues/1071)

Not sure how this case can happen but better to handle the error case.

Co-authored-by: tyranron <[email protected]>
Gustavo Garcia 4 months ago
parent
commit
d7197fa263
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/server/ns_turn_server.c

+ 4 - 0
src/server/ns_turn_server.c

@@ -4384,6 +4384,10 @@ static int create_relay_connection(turn_turnserver *server, ts_ur_super_session
 
     if (get_ioa_socket_type(newelem->s) != TCP_SOCKET) {
       if (register_callback_on_ioa_socket(server->e, newelem->s, IOA_EV_READ, peer_input_handler, ss, 0) < 0) {
+        IOA_CLOSE_SOCKET(newelem->s);
+        IOA_CLOSE_SOCKET(rtcp_s);
+        *err_code = 500;
+        *reason = (const uint8_t *)"Wrong initialization (internal error)";
         return -1;
       }
     }