summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-05-22 10:31:08 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-05-22 10:31:08 +0200
commit5da36185bde40772eb46592fcda9a4636f1c5cd4 (patch)
treefd83242e72c0a8c2d33e0eec4aef344ff6b2f2c7 /src/lib
parentd53fd8ef0228f287568cc51b87733780591308fc (diff)
parenta81e1dfb377ef3e53c2a158ea438f27773ceb25d (diff)
downloadouroboros-5da36185bde40772eb46592fcda9a4636f1c5cd4.tar.gz
ouroboros-5da36185bde40772eb46592fcda9a4636f1c5cd4.zip
Merged in dstaesse/ouroboros/be-dealloc (pull request #103)
lib, irmd, ipcpd: Flow deallocation over shim UDP
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;
}