summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-08-09 18:39:03 +0200
committerdimitri staessens <[email protected]>2016-08-09 18:40:54 +0200
commitb1d2e01f1c7c49bd2e1f926f4adb23b21ba36a4a (patch)
tree58ff91a7f218cd4d6d9795cf37c822620dd8b504 /src/lib
parente302f7c490e8ffc9a5fe74069115340230a80266 (diff)
downloadouroboros-b1d2e01f1c7c49bd2e1f926f4adb23b21ba36a4a.tar.gz
ouroboros-b1d2e01f1c7c49bd2e1f926f4adb23b21ba36a4a.zip
lib: Fix cleanup for sending messages
Cleanup handlers were not always popped.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ipcp.c22
-rw-r--r--src/lib/sockets.c21
2 files changed, 8 insertions, 35 deletions
diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c
index 76098691..141db43d 100644
--- a/src/lib/ipcp.c
+++ b/src/lib/ipcp.c
@@ -81,25 +81,11 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t api,
ipcp_msg__pack(msg, buf.data);
- if (write(sockfd, buf.data, buf.len) == -1) {
- free(buf.data);
- close(sockfd);
- return NULL;
- }
-
- count = read(sockfd, buf.data, IPCP_MSG_BUF_SIZE);
- if (count <= 0) {
- free(buf.data);
- close(sockfd);
- return NULL;
- }
+ if (write(sockfd, buf.data, buf.len) != -1)
+ count = read(sockfd, buf.data, IPCP_MSG_BUF_SIZE);
- recv_msg = ipcp_msg__unpack(NULL, count, buf.data);
- if (recv_msg == NULL) {
- free(buf.data);
- close(sockfd);
- return NULL;
- }
+ if (count > 0)
+ recv_msg = ipcp_msg__unpack(NULL, count, buf.data);
pthread_cleanup_pop(true);
pthread_cleanup_pop(true);
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index 5d861cdf..0d93c0a9 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -134,25 +134,12 @@ irm_msg_t * send_recv_irm_msg(irm_msg_t * msg)
irm_msg__pack(msg, buf.data);
- if (write(sockfd, buf.data, buf.len) == -1) {
- free(buf.data);
- close(sockfd);
- return NULL;
- }
+ if (write(sockfd, buf.data, buf.len) != -1)
+ count = read(sockfd, buf.data, IRM_MSG_BUF_SIZE);
- count = read(sockfd, buf.data, IRM_MSG_BUF_SIZE);
- if (count <= 0) {
- free(buf.data);
- close(sockfd);
- return NULL;
- }
- recv_msg = irm_msg__unpack(NULL, count, buf.data);
- if (recv_msg == NULL) {
- free(buf.data);
- close(sockfd);
- return NULL;
- }
+ if (count > 0)
+ recv_msg = irm_msg__unpack(NULL, count, buf.data);
pthread_cleanup_pop(true);
pthread_cleanup_pop(true);