summaryrefslogtreecommitdiff
path: root/src/irmd/main.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-08-09 19:51:44 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-08-09 19:51:44 +0200
commit3eb6acfd135cdfb82d19a4f445776ea2f13fd4e1 (patch)
tree96fe9ca4332c43b620f64f3f7bb4550c52191a97 /src/irmd/main.c
parentfa719e594be2a6d3132706c11166fd4ad4d57e01 (diff)
parent1c67b4cd199f9efed96468a2a2ee69fd755bcf7c (diff)
downloadouroboros-3eb6acfd135cdfb82d19a4f445776ea2f13fd4e1.tar.gz
ouroboros-3eb6acfd135cdfb82d19a4f445776ea2f13fd4e1.zip
Merged in dstaesse/ouroboros/be-bugfixing (pull request #197)
irmd: Close filedescriptor on exit
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r--src/irmd/main.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index c7c1566d..8503fcfa 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -787,10 +787,10 @@ static int flow_alloc_resp(pid_t n_api,
return -1;
}
- registry_del_api(&irmd->registry, n_api);
-
pthread_mutex_unlock(&rne->state_lock);
+ registry_del_api(&irmd->registry, n_api);
+
pthread_rwlock_unlock(&irmd->reg_lock);
if (!response) {
@@ -1401,10 +1401,11 @@ void * irm_flow_cleaner()
}
pthread_rwlock_unlock(&irmd->flows_lock);
- pthread_rwlock_wrlock(&irmd->reg_lock);
registry_sanitize_apis(&irmd->registry);
+ pthread_rwlock_wrlock(&irmd->reg_lock);
+
list_for_each_safe(pos, n, &irmd->spawned_apis) {
struct spawned_api * api =
list_entry(pos, struct spawned_api, next);
@@ -1431,6 +1432,11 @@ static void clean_msg(void * msg)
irm_msg__free_unpacked(msg, NULL);
}
+static void close_ptr(void * o)
+{
+ close(*((int *) o));
+}
+
void * mainloop()
{
uint8_t buf[IRM_MSG_BUF_SIZE];
@@ -1465,6 +1471,7 @@ void * mainloop()
continue;
}
+ pthread_cleanup_push(close_ptr, &cli_sockfd);
pthread_cleanup_push(clean_msg, (void *) msg);
switch (msg->code) {
@@ -1595,6 +1602,7 @@ void * mainloop()
}
pthread_cleanup_pop(true);
+ pthread_cleanup_pop(false);
buffer.len = irm_msg__get_packed_size(&ret_msg);
if (buffer.len == 0) {
@@ -1615,17 +1623,12 @@ void * mainloop()
irm_msg__pack(&ret_msg, buffer.data);
- if (write(cli_sockfd, buffer.data, buffer.len) == -1) {
- free(buffer.data);
- if (apis != NULL)
- free(apis);
- close(cli_sockfd);
- continue;
- }
-
if (apis != NULL)
free(apis);
+ if (write(cli_sockfd, buffer.data, buffer.len) == -1)
+ LOG_ERR("Failed to send reply message.");
+
free(buffer.data);
close(cli_sockfd);
}