]> asedeno.scripts.mit.edu Git - PuTTY.git/blobdiff - sshpubk.c
Fix a few memory leaks.
[PuTTY.git] / sshpubk.c
index 11182283f53f7a84db0cfe22d331982ed3a86f37..8b80f389959c25de251bcde25e6dd4837cfbaa3a 100644 (file)
--- a/sshpubk.c
+++ b/sshpubk.c
@@ -843,7 +843,7 @@ unsigned char *ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
     int public_blob_len;
     int i;
     const char *error = NULL;
-    char *comment;
+    char *comment = NULL;
 
     public_blob = NULL;
 
@@ -868,11 +868,10 @@ unsigned char *ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
        goto error;
     /* Select key algorithm structure. */
     alg = find_pubkey_alg(b);
+    sfree(b);
     if (!alg) {
-       sfree(b);
        goto error;
     }
-    sfree(b);
 
     /* Read the Encryption header line. */
     if (!read_header(fp, header) || 0 != strcmp(header, "Encryption"))
@@ -919,6 +918,10 @@ unsigned char *ssh2_userkey_loadpub(const Filename *filename, char **algorithm,
        sfree(public_blob);
     if (errorstr)
        *errorstr = error;
+    if (comment && commentptr) {
+        sfree(comment);
+        *commentptr = NULL;
+    }
     return NULL;
 }