Remember to close sockets on error
authorJens Axboe <axboe@kernel.dk>
Thu, 6 Oct 2011 19:27:10 +0000 (21:27 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 6 Oct 2011 19:27:10 +0000 (21:27 +0200)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
client.c
engines/net.c
server.c

index 88da9a1e6dd932aac41d2b82314588613d30393f..10d41e5b33cc738f06b25c20f074af090538cdb1 100644 (file)
--- a/client.c
+++ b/client.c
@@ -233,6 +233,7 @@ static int fio_client_connect_ip(struct fio_client *client)
        if (connect(fd, (struct sockaddr *) &client->addr, sizeof(client->addr)) < 0) {
                log_err("fio: connect: %s\n", strerror(errno));
                log_err("fio: failed to connect to %s\n", client->hostname);
        if (connect(fd, (struct sockaddr *) &client->addr, sizeof(client->addr)) < 0) {
                log_err("fio: connect: %s\n", strerror(errno));
                log_err("fio: failed to connect to %s\n", client->hostname);
+               close(fd);
                return -1;
        }
 
                return -1;
        }
 
@@ -258,6 +259,7 @@ static int fio_client_connect_sock(struct fio_client *client)
        len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
        if (connect(fd, (struct sockaddr *) addr, len) < 0) {
                log_err("fio: connect; %s\n", strerror(errno));
        len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
        if (connect(fd, (struct sockaddr *) addr, len) < 0) {
                log_err("fio: connect; %s\n", strerror(errno));
+               close(fd);
                return -1;
        }
 
                return -1;
        }
 
@@ -395,6 +397,7 @@ static int fio_client_send_ini(struct fio_client *client, const char *filename)
 
        if (fstat(fd, &sb) < 0) {
                log_err("fio: job file stat: %s\n", strerror(errno));
 
        if (fstat(fd, &sb) < 0) {
                log_err("fio: job file stat: %s\n", strerror(errno));
+               close(fd);
                return 1;
        }
 
                return 1;
        }
 
@@ -418,11 +421,13 @@ static int fio_client_send_ini(struct fio_client *client, const char *filename)
 
        if (len) {
                log_err("fio: failed reading job file %s\n", filename);
 
        if (len) {
                log_err("fio: failed reading job file %s\n", filename);
+               close(fd);
                return 1;
        }
 
        ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, sb.st_size);
        free(buf);
                return 1;
        }
 
        ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, sb.st_size);
        free(buf);
+       close(fd);
        return ret;
 }
 
        return ret;
 }
 
index faa08d5f6741b10641c36f12de933f88406846fe..d6821a4092e7898aa0fea956a6069931fde3a8b2 100644 (file)
@@ -389,6 +389,7 @@ static int fio_netio_connect(struct thread_data *td, struct fio_file *f)
 
                if (connect(f->fd, (struct sockaddr *) &nd->addr, len) < 0) {
                        td_verror(td, errno, "connect");
 
                if (connect(f->fd, (struct sockaddr *) &nd->addr, len) < 0) {
                        td_verror(td, errno, "connect");
+                       close(f->fd);
                        return 1;
                }
        } else {
                        return 1;
                }
        } else {
@@ -399,6 +400,7 @@ static int fio_netio_connect(struct thread_data *td, struct fio_file *f)
 
                if (connect(f->fd, (struct sockaddr *) addr, len) < 0) {
                        td_verror(td, errno, "connect");
 
                if (connect(f->fd, (struct sockaddr *) addr, len) < 0) {
                        td_verror(td, errno, "connect");
+                       close(f->fd);
                        return 1;
                }
        }
                        return 1;
                }
        }
@@ -543,6 +545,7 @@ static int fio_netio_setup_listen_unix(struct thread_data *td, const char *path)
 
        if (bind(fd, (struct sockaddr *) addr, len) < 0) {
                log_err("fio: bind: %s\n", strerror(errno));
 
        if (bind(fd, (struct sockaddr *) addr, len) < 0) {
                log_err("fio: bind: %s\n", strerror(errno));
+               close(fd);
                return -1;
        }
 
                return -1;
        }
 
index ba9558ce162f5065e7acbc248ab1544eab37bde1..c1a2824c12ad5675eda66a457de22811d85095ad 100644 (file)
--- a/server.c
+++ b/server.c
@@ -654,11 +654,13 @@ static int fio_init_server_ip(void)
        opt = 1;
        if (setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
                log_err("fio: setsockopt: %s\n", strerror(errno));
        opt = 1;
        if (setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
                log_err("fio: setsockopt: %s\n", strerror(errno));
+               close(sk);
                return -1;
        }
 #ifdef SO_REUSEPORT
        if (setsockopt(sk, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) {
                log_err("fio: setsockopt: %s\n", strerror(errno));
                return -1;
        }
 #ifdef SO_REUSEPORT
        if (setsockopt(sk, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) {
                log_err("fio: setsockopt: %s\n", strerror(errno));
+               close(sk);
                return -1;
        }
 #endif
                return -1;
        }
 #endif
@@ -668,6 +670,7 @@ static int fio_init_server_ip(void)
 
        if (bind(sk, (struct sockaddr *) &saddr_in, sizeof(saddr_in)) < 0) {
                log_err("fio: bind: %s\n", strerror(errno));
 
        if (bind(sk, (struct sockaddr *) &saddr_in, sizeof(saddr_in)) < 0) {
                log_err("fio: bind: %s\n", strerror(errno));
+               close(sk);
                return -1;
        }
 
                return -1;
        }
 
@@ -698,6 +701,7 @@ static int fio_init_server_sock(void)
 
        if (bind(sk, (struct sockaddr *) &addr, len) < 0) {
                log_err("fio: bind: %s\n", strerror(errno));
 
        if (bind(sk, (struct sockaddr *) &addr, len) < 0) {
                log_err("fio: bind: %s\n", strerror(errno));
+               close(sk);
                return -1;
        }
 
                return -1;
        }