mirror of
https://github.com/postgres/postgres.git
synced 2025-06-18 00:02:37 -04:00
Only free memory if environment value is replaced.
This commit is contained in:
parent
658f229ac6
commit
449e575595
@ -7,7 +7,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.63 1997/05/23 00:20:20 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.64 1997/05/23 01:53:42 momjian Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -837,6 +837,7 @@ do_connect(const char *new_dbname,
|
|||||||
else {
|
else {
|
||||||
PGconn *olddb = settings->db;
|
PGconn *olddb = settings->db;
|
||||||
static char *userenv = NULL;
|
static char *userenv = NULL;
|
||||||
|
char *old_userenv = NULL;
|
||||||
|
|
||||||
printf("closing connection to database: %s\n", dbname);
|
printf("closing connection to database: %s\n", dbname);
|
||||||
if (new_user != NULL) {
|
if (new_user != NULL) {
|
||||||
@ -845,10 +846,14 @@ do_connect(const char *new_dbname,
|
|||||||
so we have to do it via PGUSER
|
so we have to do it via PGUSER
|
||||||
*/
|
*/
|
||||||
if (userenv != NULL)
|
if (userenv != NULL)
|
||||||
free(userenv);
|
old_userenv = userenv;
|
||||||
userenv = malloc(strlen("PGUSER=") + strlen(new_user) + 1);
|
userenv = malloc(strlen("PGUSER=") + strlen(new_user) + 1);
|
||||||
sprintf(userenv,"PGUSER=%s",new_user);
|
sprintf(userenv,"PGUSER=%s",new_user);
|
||||||
putenv(userenv); /*Solaris putenv() continues to use memory in env*/
|
/* putenv() may continue to use memory as part of environment */
|
||||||
|
putenv(userenv);
|
||||||
|
/* can delete old memory if we malloc'ed it */
|
||||||
|
if (old_userenv != NULL)
|
||||||
|
free(old_userenv);
|
||||||
}
|
}
|
||||||
settings->db = PQsetdb(PQhost(olddb), PQport(olddb),
|
settings->db = PQsetdb(PQhost(olddb), PQport(olddb),
|
||||||
NULL, NULL, new_dbname);
|
NULL, NULL, new_dbname);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user