diff --git a/lib/libpam/modules/pam_unix/pam_unix.c b/lib/libpam/modules/pam_unix/pam_unix.c
index dfd7b996dc99..de7dcc8b92fd 100644
--- a/lib/libpam/modules/pam_unix/pam_unix.c
+++ b/lib/libpam/modules/pam_unix/pam_unix.c
@@ -420,6 +420,7 @@ pam_sm_chauthtok(pam_handle_t *pamh, int flags,
 			retval = PAM_SERVICE_ERR;
 		}
 #endif
+		free(old_pwd);
 	}
 	else {
 		/* Very bad juju */
@@ -427,7 +428,6 @@ pam_sm_chauthtok(pam_handle_t *pamh, int flags,
 		PAM_LOG("Illegal 'flags'");
 	}
 
-	free(old_pwd);
 	return (retval);
 }