diff options
author | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-09 17:20:36 +0200 |
---|---|---|
committer | dimitri staessens <dimitri.staessens@intec.ugent.be> | 2016-08-09 18:34:10 +0200 |
commit | 54853d3ff39079a78e9681c28d5ec65119738b18 (patch) | |
tree | e544172f18c0f0fe720feb01657d5d057be11d47 /src | |
parent | dc0e2a74d74f524f1d94140827d88479d42acd69 (diff) | |
download | ouroboros-54853d3ff39079a78e9681c28d5ec65119738b18.tar.gz ouroboros-54853d3ff39079a78e9681c28d5ec65119738b18.zip |
irmd: Close filedescriptor on exit
Diffstat (limited to 'src')
-rw-r--r-- | src/irmd/main.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c index c7c1566d..58535e27 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1431,6 +1431,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 +1470,7 @@ void * mainloop() continue; } + pthread_cleanup_push(close_ptr, &cli_sockfd); pthread_cleanup_push(clean_msg, (void *) msg); switch (msg->code) { @@ -1595,6 +1601,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 +1622,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); } |