Skip to content

Commit

Permalink
close open FDs on error, and use error path in more situations
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Mar 14, 2017
1 parent d9bfc70 commit e51af91
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/command.c
Expand Up @@ -392,7 +392,9 @@ static int fr_server_domain_socket_perm(char const *path, uid_t uid, gid_t gid)
fr_strerror_printf("Failed determining parent directory");
error:
talloc_free(dir);
close(dir_fd);
if (sock_fd >= 0) close(sock_fd);
if (dir_fd >= 0) close(dir_fd);
if (parent_fd >= 0) close(parent_fd);
return -1;
}

Expand Down Expand Up @@ -458,7 +460,7 @@ static int fr_server_domain_socket_perm(char const *path, uid_t uid, gid_t gid)
if (ret < 0) {
fr_strerror_printf("Failed changing ownership of control socket directory: %s",
fr_syserror(errno));
return -1;
goto error;
}
/*
* Control socket dir already exists, but we still need to
Expand Down Expand Up @@ -526,7 +528,7 @@ static int fr_server_domain_socket_perm(char const *path, uid_t uid, gid_t gid)
if (client_fd >= 0) {
fr_strerror_printf("Control socket '%s' is already in use", path);
close(client_fd);
return -1;
goto error;
}
}

Expand Down Expand Up @@ -675,7 +677,8 @@ static int fr_server_domain_socket_perm(char const *path, uid_t uid, gid_t gid)
if (uid != (uid_t)-1) rad_seuid(euid);
if (gid != (gid_t)-1) rad_segid(egid);

close(dir_fd);
if (dir_fd >= 0) close(dir_fd);
if (parent_fd >= 0) close(parent_fd);

return sock_fd;
}
Expand Down

0 comments on commit e51af91

Please sign in to comment.