]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Avoid leaking file handles in load_openssh_key(), as reported by David
authorSimon Tatham <anakin@pobox.com>
Thu, 30 Aug 2012 18:44:33 +0000 (18:44 +0000)
committerSimon Tatham <anakin@pobox.com>
Thu, 30 Aug 2012 18:44:33 +0000 (18:44 +0000)
Wedderwille.

[originally from svn r9642]

import.c

index 05cfdc147478f25f8cac5f455821ca5ced1d202e..2ba2f9a0e59d6b5b88460cebed47c8ff64bac494 100644 (file)
--- 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;
 }