diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-02-19 13:07:05 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-02-19 13:07:05 +0100 |
commit | 4d2d95b35addba99a7927041554d50ed7452fd7c (patch) | |
tree | a9a386df24f4c2b921476f5109f4df0ef9d4edf8 /openbsc/src/input | |
parent | 1fdbf40e8a7ca777ea6ca5c4dd70584a3fc75ed3 (diff) |
ipaccess.c: Fix some resource leaks in error conditions.
* Close the socket when the bind is failing.
* Close the socket when the listen is failing.
* Close the socket then the bsc_register_fd is failing.
* Return an error when the socket call is not returning a socket.
Diffstat (limited to 'openbsc/src/input')
-rw-r--r-- | openbsc/src/input/ipaccess.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/openbsc/src/input/ipaccess.c b/openbsc/src/input/ipaccess.c index 10a3d2283..73d798f87 100644 --- a/openbsc/src/input/ipaccess.c +++ b/openbsc/src/input/ipaccess.c @@ -598,6 +598,11 @@ static int make_sock(struct bsc_fd *bfd, u_int16_t port, bfd->when = BSC_FD_READ; //bfd->data = line; + if (bfd->fd < 0) { + LOGP(DINP, LOGL_ERROR, "could not create TCP socket.\n"); + return -EIO; + } + memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = htons(port); @@ -609,18 +614,21 @@ static int make_sock(struct bsc_fd *bfd, u_int16_t port, if (ret < 0) { LOGP(DINP, LOGL_ERROR, "could not bind l2 socket %s\n", strerror(errno)); + close(bfd->fd); return -EIO; } ret = listen(bfd->fd, 1); if (ret < 0) { perror("listen"); + close(bfd->fd); return ret; } ret = bsc_register_fd(bfd); if (ret < 0) { perror("register_listen_fd"); + close(bfd->fd); return ret; } return 0; @@ -639,6 +647,11 @@ int ipaccess_connect(struct e1inp_line *line, struct sockaddr_in *sa) bfd->data = line; bfd->priv_nr = 1; + if (bfd->fd < 0) { + LOGP(DINP, LOGL_ERROR, "could not create TCP socket.\n"); + return -EIO; + } + setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); ret = connect(bfd->fd, (struct sockaddr *) sa, sizeof(*sa)); |