From: Jiří Matěják Date: Fri, 18 May 2018 08:56:00 +0000 (+0200) Subject: free line on error X-Git-Url: https://rtime.felk.cvut.cz/gitweb/coffee/mt-apps.git/commitdiff_plain/3a4d20b35620a8478459f20dcaeb6a14cc25981a free line on error --- 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"); }