summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2023-09-10 04:14:17 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2023-09-10 04:14:17 -0500
commitb4f2469369960fb914c1d1eb4942feebf648835a (patch)
treeecaa77e92620907d275ebacdee8833342958c0a6
parent8b8aae2ac99bc91a72a32ca2040302f785e10e2b (diff)
downloadfcgiwrap-b4f2469369960fb914c1d1eb4942feebf648835a.tar.xz
fcgiwrap-b4f2469369960fb914c1d1eb4942feebf648835a.zip
Add better error handling for socket setup
-rw-r--r--fcgiwrap.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/fcgiwrap.c b/fcgiwrap.c
index cfb7797..5b8af47 100644
--- a/fcgiwrap.c
+++ b/fcgiwrap.c
@@ -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)