--- /dev/null
+--- a/svr-authpubkey.c
++++ b/svr-authpubkey.c
+@@ -167,6 +167,9 @@ out:
+ sign_key_free(key);
+ key = NULL;
+ }
++ if (!ses.authstate.authdone) {
++ svr_pubkey_options_cleanup();
++ }
+ TRACE(("leave pubkeyauth"))
+ }
+
+--- a/svr-authpubkeyoptions.c
++++ b/svr-authpubkeyoptions.c
+@@ -113,7 +113,6 @@ void svr_pubkey_options_cleanup() {
+ m_free(ses.authstate.pubkey_options->forced_command);
+ }
+ m_free(ses.authstate.pubkey_options);
+- ses.authstate.pubkey_options = NULL;
+ }
+ }
+
--- a/svr-authpubkey.c
+++ b/svr-authpubkey.c
-@@ -324,14 +324,20 @@ static int checkpubkey(const char* algo,
+@@ -327,14 +327,20 @@ static int checkpubkey(const char* algo,
goto out;
}
/* open the file as the authenticating user. */
origuid = getuid();
-@@ -408,26 +414,35 @@ static int checkpubkeyperms() {
+@@ -411,26 +417,35 @@ static int checkpubkeyperms() {
goto out;
}