summaryrefslogtreecommitdiff
path: root/src/lib/sockets.c
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-08-08 10:29:06 +0200
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-08-08 10:29:06 +0200
commitc1e1831ded0330771fd175f1c8138ed82c90f9f8 (patch)
tree617e3002ffa5addb364c01d5cd925d8c609b12b5 /src/lib/sockets.c
parentd5b71449bc18116444720257ba640e3c597ff6e9 (diff)
parent8450af0e2950e5a1415e38702d6169cc8a732294 (diff)
downloadouroboros-c1e1831ded0330771fd175f1c8138ed82c90f9f8.tar.gz
ouroboros-c1e1831ded0330771fd175f1c8138ed82c90f9f8.zip
Merged in dstaesse/ouroboros/be-bugfixing (pull request #187)
bugfixes
Diffstat (limited to 'src/lib/sockets.c')
-rw-r--r--src/lib/sockets.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index 9e13b687..5d861cdf 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -33,6 +33,8 @@
#include <sys/un.h>
#include <string.h>
#include <stdlib.h>
+#include <pthread.h>
+#include <stdbool.h>
int client_socket_open(char * file_name)
{
@@ -99,6 +101,11 @@ int server_socket_open(char * file_name)
return sockfd;
}
+void close_ptr(void * o)
+{
+ close(*(int *) o);
+}
+
irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)
{
int sockfd;
@@ -122,6 +129,9 @@ irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)
return NULL;
}
+ pthread_cleanup_push(close_ptr, &sockfd);
+ pthread_cleanup_push((void (*)(void *)) free, (void *) buf.data);
+
irm_msg__pack(msg, buf.data);
if (write(sockfd, buf.data, buf.len) == -1) {
@@ -144,8 +154,9 @@ irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)
return NULL;
}
- free(buf.data);
- close(sockfd);
+ pthread_cleanup_pop(true);
+ pthread_cleanup_pop(true);
+
return recv_msg;
}