From 3a4d20b35620a8478459f20dcaeb6a14cc25981a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Mat=C4=9Bj=C3=A1k?= Date: Fri, 18 May 2018 10:56:00 +0200 Subject: [PATCH] free line on error --- mt_server.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mt_server.c b/mt_server.c index dc70aab..fa099bb 100644 --- a/mt_server.c +++ b/mt_server.c @@ -198,6 +198,8 @@ static int callback_merica_terminal(struct lws *wsi, if (list_add(lines, line) == 0) { lws_callback_on_writable_all_protocol(lws_get_context(wsi), &protocols[PROTOCOL_MERICA_TERMINAL]); + } else { + free_line(line); } } } else if (strcmp((const char *)in, "close") == 0) { @@ -225,15 +227,16 @@ static void fd_cb(EV_P_ ev_io *w_, int revents) if (*pos == '\n' || (w->pos - w->text) == INPUT_LINE_LENGTH) { *pos = 0; - if (list_add(w->lines, w->text) == 0) { - char *line = new_line(); - if (line) { + char *line = new_line(); + if (line) { + if (list_add(w->lines, w->text) == 0) { w->text = line; w->pos = w->text; lws_callback_on_writable_all_protocol(w->context, &protocols[PROTOCOL_MERICA_TERMINAL]); return; } + free_line(line); } fprintf(stderr, "cannot malloc new line\n"); } -- 2.39.2