summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dev.c13
-rw-r--r--src/lib/sockets.c3
2 files changed, 14 insertions, 2 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 63cf92f7..d332a27f 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -202,6 +202,7 @@ int ap_reg(char ** difs,
rw_lock_wrlock(&_ap_instance->flows_lock);
fd = bmp_allocate(_ap_instance->fds);
+ _ap_instance->flows[fd].port_id = -1;
rw_lock_unlock(&_ap_instance->flows_lock);
rw_lock_unlock(&_ap_instance->data_lock);
@@ -299,8 +300,12 @@ int flow_accept(int fd,
rw_lock_rdlock(&_ap_instance->data_lock);
rw_lock_wrlock(&_ap_instance->flows_lock);
-
cfd = bmp_allocate(_ap_instance->fds);
+ if (!bmp_is_id_valid(_ap_instance->fds, cfd)) {
+ rw_lock_unlock(&_ap_instance->flows_lock);
+ rw_lock_unlock(&_ap_instance->data_lock);
+ return -1;
+ }
_ap_instance->flows[cfd].rb = shm_ap_rbuff_open(recv_msg->pid);
if (_ap_instance->flows[cfd].rb == NULL) {
@@ -405,7 +410,11 @@ int flow_alloc(char * dst_name,
rw_lock_wrlock(&_ap_instance->flows_lock);
fd = bmp_allocate(_ap_instance->fds);
-
+ if (!bmp_is_id_valid(_ap_instance->fds, fd)) {
+ rw_lock_unlock(&_ap_instance->flows_lock);
+ rw_lock_unlock(&_ap_instance->data_lock);
+ return -1;
+ }
_ap_instance->flows[fd].rb = shm_ap_rbuff_open(recv_msg->pid);
if (_ap_instance->flows[fd].rb == NULL) {
bmp_release(_ap_instance->fds, fd);
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index 4f777805..6c51e916 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -50,6 +50,7 @@ int client_socket_open(char * file_name)
(struct sockaddr *) &serv_addr,
sizeof(serv_addr))) {
LOG_ERR("Failed to connect to daemon");
+ close(sockfd);
return -1;
}
@@ -83,11 +84,13 @@ int server_socket_open(char * file_name)
(struct sockaddr *) &serv_addr,
sizeof(serv_addr))) {
LOG_ERR("Failed to bind socket");
+ close(sockfd);
return -1;
}
if (listen(sockfd, 0)) {
LOG_ERR("Failed to listen to socket");
+ close(sockfd);
return -1;
}