diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 69fac83cd58275e735be6e09d133dca1e1a683cf..6c3f0aa69d6e6b265bbea7f85912ad51214273d0 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -953,6 +953,9 @@ exec_command(const char *cmd,
 					PQclear(res);
 				PQfreemem(encrypted_password);
 			}
+
+			if (opt0)
+				free(opt0);
 		}
 
 		free(pw1);