From: simon Date: Thu, 30 Aug 2012 18:44:33 +0000 (+0000) Subject: Avoid leaking file handles in load_openssh_key(), as reported by David X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/commitdiff_plain/ae3ab75a9bc8ad74465bebda3c1bdcad9b520cb0 Avoid leaking file handles in load_openssh_key(), as reported by David Wedderwille. git-svn-id: svn://svn.tartarus.org/sgt/putty@9642 cda61777-01e9-0310-a592-d414129be87e --- diff --git a/import.c b/import.c index 05cfdc14..2ba2f9a0 100644 --- a/import.c +++ b/import.c @@ -321,7 +321,7 @@ static struct openssh_key *load_openssh_key(const Filename *filename, const char **errmsg_p) { struct openssh_key *ret; - FILE *fp; + FILE *fp = NULL; char *line = NULL; char *errmsg, *p; int headers_done; @@ -453,6 +453,9 @@ static struct openssh_key *load_openssh_key(const Filename *filename, line = NULL; } + fclose(fp); + fp = NULL; + if (ret->keyblob_len == 0 || !ret->keyblob) { errmsg = "key body not present"; goto error; @@ -483,6 +486,7 @@ static struct openssh_key *load_openssh_key(const Filename *filename, sfree(ret); } if (errmsg_p) *errmsg_p = errmsg; + if (fp) fclose(fp); return NULL; }