diff --git a/common/ratp/ratp.c b/common/ratp/ratp.c index 556dc63..d2fdb63 100644 --- a/common/ratp/ratp.c +++ b/common/ratp/ratp.c @@ -97,11 +97,24 @@ late_initcall(init_ratp_command_list); +static bool console_exists(struct console_device *cdev) +{ + struct console_device *cs; + + list_for_each_entry(cs, &console_list, list) + if (cs == cdev) + return true; + return false; +} + static int console_recv(struct ratp *r, uint8_t *data) { struct ratp_ctx *ctx = container_of(r, struct ratp_ctx, ratp); struct console_device *cdev = ctx->cdev; + if (!console_exists(cdev)) + return -ENODEV; + if (ctx->have_synch) { ctx->have_synch = 0; *data = 0x01; @@ -123,6 +136,9 @@ const uint8_t *buf = pkt; int i; + if (!console_exists(cdev)) + return -ENODEV; + for (i = 0; i < len; i++) cdev->putc(cdev, buf[i]); @@ -400,7 +416,6 @@ start = get_time_ns(); while (!ctx->fs_rx) { - poller_call(); if (ratp_closed(&ctx->ratp)) return -EIO; if (is_timeout(start, 10 * SECOND)) diff --git a/lib/ratp.c b/lib/ratp.c index 8167c5b..1901cc8 100644 --- a/lib/ratp.c +++ b/lib/ratp.c @@ -1714,6 +1714,8 @@ list_for_each_entry_safe(msg, tmp, &ri->sendmsg, list) ratp_msg_done(ri, msg, -ECONNRESET); + free(ri->recvbuf); + free(ri->sendbuf); free(ri); ratp->internal = NULL;