alfred: leaks: random fixes
cover alfred: leaks: random fixes
Similar to the batctl fixes, I have now compiled a list of potential fixes for alfred. Instead of posting everything at once, I will be posted in smaller chunks. They are just various (mostly minor) problems which should be tackled at some point.
---
Sven Eckelmann (3):
alfred: don't leak event listener when epoll registration fails
alfred: dlose the client socket on unix_sock_req_data errors
alfred: Close the periodic timer fd on setup errors
server.c | 9 +++++++-- unix_sock.c | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-)
---
base-commit: 462a0cf40615f62e0912c36d72a75accbb26f5ee
change-id: 20260731-bugfixes-leaks-988184f98f80
Best regards,
Signature · 1 line
Sven Eckelmann <[email protected]>
PATCH 1/3 alfred: don't leak event listener when epoll registration fails
unix_sock_register_listener() allocated the event listener before adding the client socket to the epoll instance. When epoll_ctl() failed, the error path only closed the client socket and the listener allocation leaked.
--- unix_sock.c | 1 + 1 file changed, 1 insertion(+)
unix_sock.c +1 -0
@@ -673,6 +673,7 @@ static int unix_sock_register_listener(struct globals *globals, int client_sock)if (epoll_ctl (globals->epollfd,EPOLL_CTL_ADD , client_sock, &ev) ==-1 ) {perror ("Failed to add epoll for event listener" ); +free (listener); goto err; }
Signature · 1 line
2.47.3
PATCH 2/3 alfred: dlose the client socket on unix_sock_req_data errors
In reply to Sven EckelmannBy the time unix_sock_req_data() runs, the accepted client socket has already been detached from its struct unix_client and removed from the epoll set; each request handler owns the fd and is expected to close it on every exit path. Two error returns did not: a request whose header.length differs from the expected size, and a failed transaction_add(). Both returned -1 without closing client_sock, leaking one file descriptor each.
--- unix_sock.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
unix_sock.c +5 -2
@@ -263,7 +263,7 @@ static int unix_sock_req_data(struct globals *globals, len =ntohs (request->header.length);if (len != (sizeof (*request) -sizeof (request->header))) -return -1 ; + goto err; id =ntohs (request->tx_id);
@@ -281,7 +281,7 @@ static int unix_sock_req_data(struct globals *globals, head =transaction_add (globals, globals->best_server->hwaddr, id);if (!head) -return -1 ; + goto err; head->client_socket = client_sock; head->requested_type = request->requested_type;
@@ -290,6 +290,9 @@ static int unix_sock_req_data(struct globals *globals, request, sizeof(*request));return 0 ; +err: +close (client_sock); +return -1 ; } int unix_sock_req_data_finish(struct globals *globals,
Signature · 1 line
2.47.3
PATCH 3/3 alfred: Close the periodic timer fd on setup errors
In reply to Sven Eckelmanncreate_sync_period_timer() created the timerfd but returned -1 without closing it when timerfd_settime() or the epoll_ctl() registration failed, leaking the descriptor. Route those failures through an error label that closes the timerfd and resets globals->check_timerfd to -1.
--- server.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
server.c +7 -2
@@ -440,7 +440,7 @@ static int create_sync_period_timer(struct globals *globals) ret =timerfd_settime (globals->check_timerfd,0 , &sync_timer,NULL );if (ret <0 ) {perror ("Failed to arm synchronization timer" ); -return -1 ; + goto err; } ev.events =EPOLLIN ;
@@ -450,10 +450,15 @@ static int create_sync_period_timer(struct globals *globals)if (epoll_ctl (globals->epollfd,EPOLL_CTL_ADD , globals->check_timerfd, &ev) ==-1 ) {perror ("Failed to add epoll for check_timer" ); -return -1 ; + goto err; }return 0 ; + +err: +close (globals->check_timerfd); + globals->check_timerfd =-1 ; +return -1 ; }int alfred_server (struct globals *globals)
Signature · 1 line
2.47.3