Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit148f720

Browse files
committed
Preserve putenv() memory in psql \connect user fix.
1 parent65ff0fe commit148f720

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

‎src/bin/psql/psql.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.61 1997/05/2218:55:35 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/psql.c,v 1.62 1997/05/2223:57:27 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -836,18 +836,19 @@ do_connect(const char *new_dbname,
836836
fprintf(stderr,"\\connect must be followed by a database name\n");
837837
else {
838838
PGconn*olddb=settings->db;
839-
char*userenv;
839+
staticchar*userenv=NULL;
840840

841841
printf("closing connection to database: %s\n",dbname);
842842
if (new_user!=NULL) {
843843
/*
844844
PQsetdb() does not allow us to specify the user,
845845
so we have to do it via PGUSER
846846
*/
847+
if (userenv!=NULL)
848+
free(userenv);
847849
userenv=malloc(strlen("PGUSER=")+strlen(new_user)+1);
848850
sprintf(userenv,"PGUSER=%s",new_user);
849-
putenv(userenv);
850-
free(userenv);
851+
putenv(userenv);/* putenv() continues to use memory in env. */
851852
}
852853
settings->db=PQsetdb(PQhost(olddb),PQport(olddb),
853854
NULL,NULL,new_dbname);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp