Browse Source

close socket to avoid memory leak when error occurs

pull/2842/head
Gilles Depeyrot 3 years ago
committed by Max Lv
parent
commit
a19328a977
1 changed files with 2 additions and 0 deletions
  1. 2
      src/plugin.c

2
src/plugin.c

@ -313,11 +313,13 @@ get_local_port()
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = 0;
if (bind(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
close(sock);
return 0;
}
socklen_t len = sizeof(serv_addr);
if (getsockname(sock, (struct sockaddr *)&serv_addr, &len) == -1) {
close(sock);
return 0;
}
if (close(sock) < 0) {

Loading…
Cancel
Save