7
7
*
8
8
*
9
9
* IDENTIFICATION
10
- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.63 1997/05/2300:20:20 momjian Exp $
10
+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.64 1997/05/2301:53:42 momjian Exp $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -837,6 +837,7 @@ do_connect(const char *new_dbname,
837
837
else {
838
838
PGconn * olddb = settings -> db ;
839
839
static char * userenv = NULL ;
840
+ char * old_userenv = NULL ;
840
841
841
842
printf ("closing connection to database: %s\n" ,dbname );
842
843
if (new_user != NULL ) {
@@ -845,10 +846,14 @@ do_connect(const char *new_dbname,
845
846
so we have to do it via PGUSER
846
847
*/
847
848
if (userenv != NULL )
848
- free ( userenv ) ;
849
+ old_userenv = userenv ;
849
850
userenv = malloc (strlen ("PGUSER=" )+ strlen (new_user )+ 1 );
850
851
sprintf (userenv ,"PGUSER=%s" ,new_user );
851
- putenv (userenv );/*Solaris putenv() continues to use memory in env*/
852
+ /* putenv() may continue to use memory as part of environment */
853
+ putenv (userenv );
854
+ /* can delete old memory if we malloc'ed it */
855
+ if (old_userenv != NULL )
856
+ free (old_userenv );
852
857
}
853
858
settings -> db = PQsetdb (PQhost (olddb ),PQport (olddb ),
854
859
NULL ,NULL ,new_dbname );