diff options
author | Dimitri Staessens <[email protected]> | 2024-02-24 12:52:20 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2024-02-26 08:59:15 +0100 |
commit | 82aec24db65fd3bf06f60a8952c1b0b3dfd05ec4 (patch) | |
tree | 8758742320d4c7c63c128c4c9c8ac69f795001e4 /src/irmd/main.c | |
parent | b5888ad746fd03d483196a2cb3711bb0fe63d82d (diff) | |
download | ouroboros-82aec24db65fd3bf06f60a8952c1b0b3dfd05ec4.tar.gz ouroboros-82aec24db65fd3bf06f60a8952c1b0b3dfd05ec4.zip |
irmd: Fix memleak on cancel
If the mainloop is cancelled during a write, the response buffer
leaks.
The IRMd now warns about failed writes only when the error is not
EPIPE, as EPIPE is expected to happen with timed out requests.
Signed-off-by: Dimitri Staessens <[email protected]>
Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/irmd/main.c')
-rw-r--r-- | src/irmd/main.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c index ecdc2fb9..6e1a1262 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1536,6 +1536,7 @@ static void * mainloop(void * o) free(cmd); if (msg == NULL) { + log_err("Failed to unpack command message."); close(sfd); continue; } @@ -1582,12 +1583,18 @@ static void * mainloop(void * o) irm_msg__free_unpacked(ret_msg, NULL); pthread_cleanup_push(__cleanup_close_ptr, &sfd); + pthread_cleanup_push(free, buffer.data); + + if (write(sfd, buffer.data, buffer.len) == -1) { + if (errno != EPIPE) + log_warn("Failed to send reply message: %s.", + strerror(errno)); + else + log_dbg("Failed to send reply message: %s.", + strerror(errno)); + } - if (write(sfd, buffer.data, buffer.len) == -1) - log_warn("Failed to send reply message."); - - free(buffer.data); - + pthread_cleanup_pop(true); pthread_cleanup_pop(true); tpm_inc(irmd.tpm); |