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.
diff --git a/openbsc/src/input/ipaccess.c b/openbsc/src/input/ipaccess.c
index 10a3d22..73d798f 100644
--- a/openbsc/src/input/ipaccess.c
+++ b/openbsc/src/input/ipaccess.c
@@ -598,6 +598,11 @@
 	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 @@
 	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 @@
 	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));