@@ -739,7 +739,8 @@ static int
739739pg_password_sendauth (PGconn * conn ,const char * password ,AuthRequest areq )
740740{
741741int ret ;
742- char * crypt_pwd ;
742+ char * crypt_pwd = NULL ;
743+ const char * pwd_to_send ;
743744
744745/* Encrypt the password if needed. */
745746
@@ -771,21 +772,22 @@ pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
771772free (crypt_pwd );
772773return STATUS_ERROR ;
773774}
775+
776+ pwd_to_send = crypt_pwd ;
774777break ;
775778}
776779case AUTH_REQ_PASSWORD :
777- /* discard const so we can assign it */
778- crypt_pwd = (char * )password ;
780+ pwd_to_send = password ;
779781break ;
780782default :
781783return STATUS_ERROR ;
782784}
783785/* Packet has a message type as of protocol 3.0 */
784786if (PG_PROTOCOL_MAJOR (conn -> pversion ) >=3 )
785- ret = pqPacketSend (conn ,'p' ,crypt_pwd ,strlen (crypt_pwd )+ 1 );
787+ ret = pqPacketSend (conn ,'p' ,pwd_to_send ,strlen (pwd_to_send )+ 1 );
786788else
787- ret = pqPacketSend (conn ,0 ,crypt_pwd ,strlen (crypt_pwd )+ 1 );
788- if (areq == AUTH_REQ_MD5 )
789+ ret = pqPacketSend (conn ,0 ,pwd_to_send ,strlen (pwd_to_send )+ 1 );
790+ if (crypt_pwd )
789791free (crypt_pwd );
790792return ret ;
791793}