Skip to content

Commit

Permalink
close socket to avoid memory leak when error occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
gdepeyrot authored and Max Lv committed Jul 16, 2021
1 parent 8bcffa5 commit a19328a
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a19328a

Please sign in to comment.