From 2d4a615a721c3e9ba052f593988ba0d9c3abd84b Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 4 Jul 2023 22:33:26 +0200 Subject: worker: close the leftover descriptor Thanks, Valgrind! As a note: if I think that Valgrind reports a false positive, chances are, it's not. --- src/worker.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/worker.c b/src/worker.c index 3bd2155..d7cd610 100644 --- a/src/worker.c +++ b/src/worker.c @@ -208,36 +208,39 @@ void worker_destroy(struct worker *worker) int worker_main(struct worker *worker) { - int ret = 0; + int ret = 0, fd = -1; while (!worker->stopping) { ret = net_connect(worker->settings->host, worker->settings->port); if (ret < 0) return ret; + fd = ret; - const int fd = ret; struct msg *new_worker_msg = NULL; ret = msg_new_worker_create(&new_worker_msg); if (ret < 0) - return ret; + goto close; ret = msg_send(fd, new_worker_msg); msg_free(new_worker_msg); if (ret < 0) - return ret; + goto close; ret = event_loop_add_once(worker->event_loop, fd, POLLIN, cmd_dispatcher_handle_event, worker->cmd_dispatcher); if (ret < 0) - return ret; + goto close; log("Waiting for a new command\n"); ret = event_loop_run(worker->event_loop); if (ret < 0) - return ret; + goto close; } +close: + net_close(fd); + return ret; } -- cgit v1.2.3