summaryrefslogtreecommitdiff
path: root/src/lib/ipcp.c
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2016-08-08 10:29:06 +0200
committerSander Vrijders <[email protected]>2016-08-08 10:29:06 +0200
commitc1e1831ded0330771fd175f1c8138ed82c90f9f8 (patch)
tree617e3002ffa5addb364c01d5cd925d8c609b12b5 /src/lib/ipcp.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/ipcp.c')
-rw-r--r--src/lib/ipcp.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c
index 373baafd..76098691 100644
--- a/src/lib/ipcp.c
+++ b/src/lib/ipcp.c
@@ -34,9 +34,15 @@
#include <string.h>
#include <signal.h>
#include <stdbool.h>
+#include <pthread.h>
#include <sys/types.h>
#include <sys/wait.h>
+static void close_ptr(void * o)
+{
+ close(*((int *) o));
+}
+
static ipcp_msg_t * send_recv_ipcp_msg(pid_t api,
ipcp_msg_t * msg)
{
@@ -56,24 +62,26 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t api,
return NULL;
}
+ free(sock_path);
+
buf.len = ipcp_msg__get_packed_size(msg);
if (buf.len == 0) {
close(sockfd);
- free(sock_path);
return NULL;
}
buf.data = malloc(IPCP_MSG_BUF_SIZE);
if (buf.data == NULL) {
close(sockfd);
- free(sock_path);
return NULL;
}
+ pthread_cleanup_push(close_ptr, (void *) &sockfd);
+ pthread_cleanup_push((void (*)(void *)) free, (void *) buf.data);
+
ipcp_msg__pack(msg, buf.data);
if (write(sockfd, buf.data, buf.len) == -1) {
- free(sock_path);
free(buf.data);
close(sockfd);
return NULL;
@@ -81,7 +89,6 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t api,
count = read(sockfd, buf.data, IPCP_MSG_BUF_SIZE);
if (count <= 0) {
- free(sock_path);
free(buf.data);
close(sockfd);
return NULL;
@@ -89,15 +96,14 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t api,
recv_msg = ipcp_msg__unpack(NULL, count, buf.data);
if (recv_msg == NULL) {
- free(sock_path);
free(buf.data);
close(sockfd);
return NULL;
}
- free(buf.data);
- free(sock_path);
- close(sockfd);
+ pthread_cleanup_pop(true);
+ pthread_cleanup_pop(true);
+
return recv_msg;
}