Browse Source

Memory leak when parsing of public key fails

Source commit: f3ead13d4f12625882856c7c0211a62608f03e9f
Martin Prikryl 1 year ago
parent
commit
6c36444701
1 changed files with 12 additions and 12 deletions
  1. 12 12
      source/core/PuttyIntf.cpp

+ 12 - 12
source/core/PuttyIntf.cpp

@@ -1204,13 +1204,13 @@ UnicodeString __fastcall ParseOpenSshPubLine(const UnicodeString & Line, const s
   BinarySource Source[1];
   BinarySource_BARE_INIT(Source, UtfLine.c_str(), UtfLine.Length());
   UnicodeString Result;
-  if (!openssh_loadpub(Source, &AlgorithmName, BinarySink_UPCAST(PubBlobBuf), &CommentPtr, &ErrorStr))
-  {
-    throw Exception(UnicodeString(ErrorStr));
-  }
-  else
+  try
   {
-    try
+    if (!openssh_loadpub(Source, &AlgorithmName, BinarySink_UPCAST(PubBlobBuf), &CommentPtr, &ErrorStr))
+    {
+      throw Exception(UnicodeString(ErrorStr));
+    }
+    else
     {
       Algorithm = find_pubkey_alg(AlgorithmName);
       if (Algorithm == NULL)
@@ -1229,12 +1229,12 @@ UnicodeString __fastcall ParseOpenSshPubLine(const UnicodeString & Line, const s
       sfree(FmtKey);
       Algorithm->freekey(Key);
     }
-    __finally
-    {
-      strbuf_free(PubBlobBuf);
-      sfree(AlgorithmName);
-      sfree(CommentPtr);
-    }
+  }
+  __finally
+  {
+    strbuf_free(PubBlobBuf);
+    sfree(AlgorithmName);
+    sfree(CommentPtr);
   }
   return Result;
 }