Browse code

ims_ipsec_pcscf: closing mnl_socket in some exceptional situations

- fix leak socket when error handling errors in creation or destruction ipsec tunnel

Stanislav S. Litvinenko authored on 30/10/2019 23:17:54
Showing 1 changed files
... ...
@@ -338,15 +338,18 @@ static int create_ipsec_tunnel(const struct ip_addr *remote_addr, ipsec_t* s)
338 338
     if(remote_addr->af == AF_INET){
339 339
         if(str2ipbuf(&ipsec_listen_addr, &ipsec_addr) < 0){
340 340
             LM_ERR("Unable to convert ipsec addr4 [%.*s]\n", ipsec_listen_addr.len, ipsec_listen_addr.s);
341
+            close_mnl_socket(sock);
341 342
             return 0;
342 343
         }
343 344
     } else if(remote_addr->af == AF_INET6){
344 345
         if(str2ip6buf(&ipsec_listen_addr6, &ipsec_addr) < 0){
345 346
             LM_ERR("Unable to convert ipsec addr6 [%.*s]\n", ipsec_listen_addr6.len, ipsec_listen_addr6.s);
347
+            close_mnl_socket(sock);
346 348
             return 0;
347 349
         }
348 350
     } else {
349 351
         LM_ERR("Unsupported AF %d\n", remote_addr->af);
352
+        close_mnl_socket(sock);
350 353
         return 0;
351 354
     }
352 355
 
... ...
@@ -355,6 +358,7 @@ static int create_ipsec_tunnel(const struct ip_addr *remote_addr, ipsec_t* s)
355 355
     memset(remote_addr_str, 0, sizeof(remote_addr_str));
356 356
     if(inet_ntop(remote_addr->af, remote_addr->u.addr, remote_addr_str, sizeof(remote_addr_str)) == NULL) {
357 357
         LM_CRIT("Error converting remote IP address: %s\n", strerror(errno));
358
+        close_mnl_socket(sock);
358 359
         return -1;
359 360
     }
360 361
 
... ...
@@ -401,6 +405,7 @@ static int destroy_ipsec_tunnel(str remote_addr, ipsec_t* s, unsigned short rece
401 401
     // convert 'remote_addr' ip string to ip_addr_t
402 402
     if(str2ipxbuf(&remote_addr, &ip_addr) < 0){
403 403
         LM_ERR("Unable to convert remote address [%.*s]\n", remote_addr.len, remote_addr.s);
404
+        close_mnl_socket(sock);
404 405
         return -1;
405 406
     }
406 407