mirror of
https://github.com/postgres/postgres.git
synced 2025-04-24 10:47:04 +03:00
Preserve putenv() memory in psql \connect user fix.
This commit is contained in:
parent
65ff0feacf
commit
148f7203fa
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.61 1997/05/22 18:55:35 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.62 1997/05/22 23:57:27 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -836,7 +836,7 @@ do_connect(const char *new_dbname,
|
||||
fprintf(stderr, "\\connect must be followed by a database name\n");
|
||||
else {
|
||||
PGconn *olddb = settings->db;
|
||||
char *userenv;
|
||||
static char *userenv = NULL;
|
||||
|
||||
printf("closing connection to database: %s\n", dbname);
|
||||
if (new_user != NULL) {
|
||||
@ -844,10 +844,11 @@ do_connect(const char *new_dbname,
|
||||
PQsetdb() does not allow us to specify the user,
|
||||
so we have to do it via PGUSER
|
||||
*/
|
||||
if (userenv != NULL)
|
||||
free(userenv);
|
||||
userenv = malloc(strlen("PGUSER=") + strlen(new_user) + 1);
|
||||
sprintf(userenv,"PGUSER=%s",new_user);
|
||||
putenv(userenv);
|
||||
free(userenv);
|
||||
putenv(userenv); /* putenv() continues to use memory in env. */
|
||||
}
|
||||
settings->db = PQsetdb(PQhost(olddb), PQport(olddb),
|
||||
NULL, NULL, new_dbname);
|
||||
|
Loading…
x
Reference in New Issue
Block a user