From 85b1916ca601b309c3b75f55d4d15843c452ba96 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 29 Jan 2019 20:11:46 +0000 Subject: [PATCH] Fix memory leak in rsa_ssh1_savekey. The strbuf containing the data of the output key file was never freed. --- sshpubk.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sshpubk.c b/sshpubk.c index 720387a2..40382656 100644 --- a/sshpubk.c +++ b/sshpubk.c @@ -371,13 +371,14 @@ bool rsa_ssh1_savekey(const Filename *filename, RSAKey *key, * Done. Write the result to the file. */ fp = f_open(filename, "wb", true); + bool ret = false; if (fp) { - bool ret = (fwrite(buf->u, 1, buf->len, fp) == (size_t) (buf->len)); + ret = (fwrite(buf->u, 1, buf->len, fp) == (size_t) (buf->len)); if (fclose(fp)) ret = false; - return ret; - } else - return false; + } + strbuf_free(buf); + return ret; } /* ----------------------------------------------------------------------