diff options
| author | 2023-11-06 13:42:31 -0500 | |
|---|---|---|
| committer | 2023-11-06 13:42:31 -0500 | |
| commit | b0f53d634813af0a038d4faf6fa71d90d9aa0845 (patch) | |
| tree | 764ebd8613cdaa3c5eadb85dc226365e533b20ad /src | |
| parent | af20c37fb2b2eb929e9175ce9b568a636f72d93a (diff) | |
| download | libnaunet-b0f53d634813af0a038d4faf6fa71d90d9aa0845.tar.gz libnaunet-b0f53d634813af0a038d4faf6fa71d90d9aa0845.tar.bz2 libnaunet-b0f53d634813af0a038d4faf6fa71d90d9aa0845.zip | |
Fix deinitialization in aki_line_processor
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src')
| -rw-r--r-- | src/line_processor.c | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/line_processor.c b/src/line_processor.c index 758f99c..de86dab 100644 --- a/src/line_processor.c +++ b/src/line_processor.c @@ -8,6 +8,22 @@ #define CHUNK_SIZE 512 #define END al_str_c("X") +static void remove_client(struct aki_line_processor *pro, struct aki_line_processor_client *client) +{ + ev_io_stop(pro->loop->ev, &client->event); + if (client->pro->type == AKI_LINE_PROCESSOR_SOCKET) { + aki_socket_close(&client->s); + } + aki_buffer_free(&client->buf); + struct aki_line_processor_client *rclient; + al_array_foreach(pro->clients, i, rclient) { + if (rclient == client) { + al_array_remove_at_iter(pro->clients, i); + } + } + al_free(client); +} + static void read_callback(struct ev_loop *loop, ev_io *w, s32 revents) { (void)loop; @@ -33,12 +49,7 @@ static void read_callback(struct ev_loop *loop, ev_io *w, s32 revents) if (al_str_cmp(al_str_w((char *)ptr, i, (u32)(client->index - i)), delim, 0, delim->len) == 0) { str *s = al_str_w((char *)ptr, 0, i); if (al_str_eq(s, END)) { - ev_io_stop(client->pro->loop->ev, &client->event); - if (client->pro->type == AKI_LINE_PROCESSOR_SOCKET) { - aki_socket_close(&client->s); - } - aki_buffer_free(&client->buf); - al_free(client); + remove_client(client->pro, client); return; } switch (client->pro->callback(client->pro->userdata, s)) { @@ -82,6 +93,7 @@ static void socket_connection_callback(struct ev_loop *loop, ev_io *w, s32 reven void aki_line_processor_init(struct aki_line_processor *pro, str *delim) { + pro->loop = NULL; al_str_clone(&pro->delim, delim); al_array_init(pro->clients); } @@ -124,16 +136,18 @@ void aki_line_processor_run(struct aki_line_processor *pro, struct aki_event_loo void aki_line_processor_stop(struct aki_line_processor *pro) { - switch (pro->type) { - case AKI_LINE_PROCESSOR_SOCKET: - ev_io_stop(pro->loop->ev, &pro->event); - break; - case AKI_LINE_PROCESSOR_FD: - break; - } - struct aki_line_processor_client *client; - al_array_foreach(pro->clients, i, client) { - ev_io_stop(pro->loop->ev, &client->event); + if (pro->loop) { + switch (pro->type) { + case AKI_LINE_PROCESSOR_SOCKET: + ev_io_stop(pro->loop->ev, &pro->event); + break; + case AKI_LINE_PROCESSOR_FD: + break; + } + struct aki_line_processor_client *client; + al_array_foreach(pro->clients, i, client) { + remove_client(client->pro, client); + } } al_array_free(pro->clients); } |