From: Petr Štetiar Date: Mon, 16 Dec 2019 13:49:40 +0000 (+0100) Subject: fix leaking memory in cert_dump_blob X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=19a7225ac0188f3b3945b5608e02fc0101127bbd;p=oweals%2Fucert.git fix leaking memory in cert_dump_blob Fixes following valgrind reported memory leak: 189 bytes in 1 blocks are definitely lost in loss record 3 of 4 at realloc by blobmsg_format_json_with_cb by blobmsg_format_json_indent by cert_dump_blob (ucert.c:386) by cert_dump (ucert.c:405) by main (ucert.c:728) Signed-off-by: Petr Štetiar --- diff --git a/ucert.c b/ucert.c index b9c5c88..76960a2 100644 --- a/ucert.c +++ b/ucert.c @@ -371,6 +371,7 @@ clean_and_return: /* dump single chain element to console */ static void cert_dump_blob(struct blob_attr *cert[CERT_ATTR_MAX]) { int i; + char *json = NULL; for (i = 0; i < CERT_ATTR_MAX; i++) { struct blob_attr *v = cert[i]; @@ -383,7 +384,13 @@ static void cert_dump_blob(struct blob_attr *cert[CERT_ATTR_MAX]) { fprintf(stdout, "signature:\n---\n%s---\n", (char *) blob_data(v)); break; case BLOB_ATTR_NESTED: - fprintf(stdout, "payload:\n---\n%s\n---\n", blobmsg_format_json_indent(blob_data(v), false, 0)); + json = blobmsg_format_json_indent(blob_data(v), false, 0); + if (!json) { + DPRINTF("cannot parse payload\n"); + continue; + } + fprintf(stdout, "payload:\n---\n%s\n---\n", json); + free(json); break; } }