From b1d2e01f1c7c49bd2e1f926f4adb23b21ba36a4a Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Tue, 9 Aug 2016 18:39:03 +0200 Subject: lib: Fix cleanup for sending messages Cleanup handlers were not always popped. --- src/lib/sockets.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'src/lib/sockets.c') 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); -- cgit v1.2.3