diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-04 22:33:26 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-07-04 22:39:26 +0200 |
commit | 2d4a615a721c3e9ba052f593988ba0d9c3abd84b (patch) | |
tree | 3c23998a50f34bdbaaf47ce35502e9062b8c1f1b | |
parent | move custom message parsing to a separate module (diff) | |
download | cimple-2d4a615a721c3e9ba052f593988ba0d9c3abd84b.tar.gz cimple-2d4a615a721c3e9ba052f593988ba0d9c3abd84b.zip |
worker: close the leftover descriptor
Thanks, Valgrind! As a note: if I think that Valgrind reports a false
positive, chances are, it's not.
Diffstat (limited to '')
-rw-r--r-- | src/worker.c | 15 |
1 files changed, 9 insertions, 6 deletions
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; } |