Commit 1c1308a1 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

[1705] Don't leak the fd on close error

parent 16b39f3c
......@@ -111,7 +111,14 @@ recv_fd(const int sock) {
// one returned previously, even if that one is not closed yet. So,
// we just re-number every one we get, so they are unique.
int new_fd(dup(fd));
if (close(fd) == -1 || new_fd == -1) {
int close_error(close(fd));
if (close_error == -1 || new_fd == -1) {
// We need to return an error, because something failed. But in case
// it was the previous close, we at least try to close the duped FD.
if (new_fd != -1) {
close(new_fd); // If this fails, nothing but returning error can't
// be done and we are doing that anyway.
return (new_fd);
Supports Markdown
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