diff options
author | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-09-10 04:14:17 -0500 |
---|---|---|
committer | flu0r1ne <flu0r1ne@flu0r1ne.net> | 2023-09-10 04:14:17 -0500 |
commit | b4f2469369960fb914c1d1eb4942feebf648835a (patch) | |
tree | ecaa77e92620907d275ebacdee8833342958c0a6 | |
parent | 8b8aae2ac99bc91a72a32ca2040302f785e10e2b (diff) | |
download | fcgiwrap-b4f2469369960fb914c1d1eb4942feebf648835a.tar.xz fcgiwrap-b4f2469369960fb914c1d1eb4942feebf648835a.zip |
Add better error handling for socket setup
-rw-r--r-- | fcgiwrap.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -793,18 +793,30 @@ invalid_url: fd = socket(sa.sa.sa_family, SOCK_STREAM, 0); if (fd < 0) { perror("Failed to create socket"); - return -1; + goto cleanup_socket; } if (bind(fd, &sa.sa, sockaddr_size) < 0) { perror("Failed to bind"); - return -1; + goto cleanup_fd; } if (listen_on_fd(fd) < 0) { - return -1; + goto cleanup_fd; } return fd; + +cleanup_fd: + + close(fd); + +cleanup_socket: + + if(sa.sa.sa_family == AF_UNIX) { + unlink(sa.sa_un.sun_path); + } + + return -1; } int main(int argc, char **argv) |